2 #include <Wt/WStandardItemModel.h> 3 #include <Wt/WCalendar.h> 4 #include <Wt/WHBoxLayout.h> 5 #include <Wt/WPushButton.h> 6 #include <Wt/WComboBox.h> 7 #include <Wt/WStackedWidget.h> 8 #include <Wt/WTemplate.h> 12 #define COUT_(X) std::cout << __FILE__ << "::" << __LINE__ << " " << X << std::endl; 13 #define COUT_LINE COUT_(""); 16 Wtx::Web::Calendar::Widget::ToolBar::ToolBar()
18 addStyleClass(
"form-inline");
19 auto templt = addNew<Wt::WTemplate>( Wt::WString::tr(
"Wtx.Calendar.toolBar" ) );
21 m_pbNew = templt-> bindNew<Wt::WPushButton>(
"new", Wt::WString::tr(
"Wtx.Calendar.Widget.new") );
22 m_pbToday = templt-> bindNew<Wt::WPushButton>(
"today", Wt::WString::tr(
"Wtx.Calendar.Widget.today") );
23 m_pbPrev = templt-> bindNew<Wt::WPushButton>(
"previous", Wt::WString::tr(
"Wtx.Calendar.Widget.previous") );
24 m_pbNext = templt-> bindNew<Wt::WPushButton>(
"next", Wt::WString::tr(
"Wtx.Calendar.Widget.next") );
25 m_pbFind = templt-> bindNew<Wt::WPushButton>(
"find", Wt::WString::tr(
"Wtx.Calendar.Widget.find") );
26 m_cbView = templt-> bindNew<Wt::WComboBox>(
"view" );
27 m_pbSett = templt-> bindNew<Wt::WPushButton>(
"settings", Wt::WString::tr(
"Wtx.Calendar.Widget.settings") );
29 m_cbView-> addItem( Wt::WString::tr(
"Wtx.Calendar.Widget.View.day" ) );
30 m_cbView-> addItem( Wt::WString::tr(
"Wtx.Calendar.Widget.View.week" ) );
31 m_cbView-> addItem( Wt::WString::tr(
"Wtx.Calendar.Widget.View.month" ) );
32 m_cbView-> addItem( Wt::WString::tr(
"Wtx.Calendar.Widget.View.year" ) );
33 m_cbView-> addItem( Wt::WString::tr(
"Wtx.Calendar.Widget.View.schedule" ) );
34 m_cbView-> addItem( Wt::WString::tr(
"Wtx.Calendar.Widget.View.4-days" ) );
35 m_cbView-> addItem( Wt::WString::tr(
"Wtx.Calendar.Widget.View.5-days" ) );
36 m_cbView-> addItem( Wt::WString::tr(
"Wtx.Calendar.Widget.View.table" ) );
38 m_date = templt-> bindNew<Wt::WText>(
"date" );
42 Wt::WPushButton * Wtx::Web::Calendar::Widget::ToolBar::pbNew()
const 47 Wt::WPushButton * Wtx::Web::Calendar::Widget::ToolBar::pbToday()
const 52 Wt::WPushButton * Wtx::Web::Calendar::Widget::ToolBar::pbPrev()
const 57 Wt::WPushButton * Wtx::Web::Calendar::Widget::ToolBar::pbNext()
const 62 Wt::WPushButton * Wtx::Web::Calendar::Widget::ToolBar::pbFind()
const 67 Wt::WComboBox * Wtx::Web::Calendar::Widget::ToolBar::cbView()
const 72 Wt::WPushButton * Wtx::Web::Calendar::Widget::ToolBar::pbSett()
const 78 Wtx::Web::Calendar::Widget::SideBar::SideBar(
int firstDayOfWeek )
80 m_calendar = addNew<Wt::WCalendar>();
81 m_calendar-> addStyleClass(
"calendarPicker" );
82 m_calendar-> setSelectionMode( Wt::SelectionMode::Single );
83 m_calendar-> setFirstDayOfWeek( firstDayOfWeek );
86 Wt::WCalendar * Wtx::Web::Calendar::Widget::SideBar::calendar()
const 91 int range(
int value,
int minimum,
int maximum )
103 : m_database( database )
118 firstDayOfWeek = range( firstDayOfWeek, 1, 7 );
120 m_selectedDate = Wt::WDate::currentDate();
122 auto u_lw = std::make_unique<Wt::WHBoxLayout>();
123 auto lw = u_lw.get();
124 setLayout( std::move(u_lw) );
126 auto u_sideBar = std::make_unique<Wtx::Web::Calendar::Widget::SideBar>( firstDayOfWeek );
127 m_sideBar = u_sideBar.get();
128 lw-> addWidget( std::move( u_sideBar ) );
129 m_sideBar-> calendar()-> clicked().connect( [=]( )
131 if( m_sideBar-> calendar()-> selection().size() > 0 )
133 setSelectedDate( *(m_sideBar-> calendar()-> selection().begin()) );
137 auto u_templt = std::make_unique<Wt::WTemplate>( Wt::WString::tr(
"Wtx.Calendar.widget" ) );
138 auto m_templt = u_templt.get();
140 lw-> addWidget( std::move(u_templt), 1 );
142 m_toolBar = m_templt-> bindNew<ToolBar>(
"toolBar" );
144 m_toolBar-> pbNew()-> clicked().connect( [=]()
146 m_itemNew.emit( selectedDate() );
149 m_toolBar-> pbToday()-> clicked().connect( [=]()
151 setSelectedDate( Wt::WDate::currentDate() );
154 m_toolBar-> pbPrev()-> clicked().connect( [=]()
159 m_toolBar-> pbNext()-> clicked().connect( [=]()
164 m_toolBar-> cbView()-> activated().connect( [=](
int value )
169 m_stack = m_templt-> bindNew<Wt::WStackedWidget>(
"stack" );
171 auto u_dayView = std::make_unique<Wtx::Web::Calendar::DayView>(firstDayOfWeek,
this);
172 m_dayView = u_dayView.get();
173 m_stack-> addWidget( std::move(u_dayView) );
175 auto u_weekView = std::make_unique<Wtx::Web::Calendar::WeekView>(firstDayOfWeek,
this);
176 m_weekView = u_weekView.get();
177 m_stack-> addWidget( std::move(u_weekView) );
179 auto u_monthView = std::make_unique<Wtx::Web::Calendar::MonthView>(firstDayOfWeek,
this);
180 m_monthView = u_monthView.get();
181 m_stack-> addWidget( std::move(u_monthView) );
182 m_monthView-> clicked().connect( [=]( Wt::WDate date )
184 setSelectedDate( date );
186 m_monthView-> itemClicked().connect( [=]( Wt::WModelIndex index )
188 m_itemClicked.emit( index );
190 m_monthView-> itemDoubleClicked().connect( [=]( Wt::WModelIndex index )
192 m_itemDoubleClicked.emit( index );
195 auto u_yearView = std::make_unique<Wtx::Web::Calendar::YearView>(firstDayOfWeek,
this);
196 m_yearView = u_yearView.get();
197 m_stack-> addWidget( std::move(u_yearView) );
199 auto u_scheduleView = std::make_unique<Wt::WText>(
"schedule");
200 m_stack-> addWidget( std::move(u_scheduleView) );
202 auto u_fourDaysView = std::make_unique<Wt::WText>(
"4-days");
203 m_stack-> addWidget( std::move(u_fourDaysView) );
205 auto u_fiveDaysView = std::make_unique<Wt::WText>(
"5-days");
206 m_stack-> addWidget( std::move(u_fiveDaysView) );
208 auto u_tableView = std::make_unique<Wt::WText>(
"Table");
209 m_stack-> addWidget( std::move(u_tableView) );
213 std::map< Wt::WDate, std::string > holidays =
215 { Wt::WDate( 2018, 5, 5 ),
"Cinco de Mayo" },
216 { Wt::WDate( 2018, 5, 10 ),
"Ascension Day" },
217 { Wt::WDate( 2018, 5, 13 ),
"Mother's Day" },
218 { Wt::WDate( 2018, 5, 21 ),
"Victoria Day (Canada)" },
219 { Wt::WDate( 2018, 5, 28 ),
"Memorial Day (USA)" }
222 for(
auto calendarDay : monthView()-> dayWidgets() )
224 auto holidayItem = holidays.find( calendarDay-> date() );
225 if( holidayItem != holidays.end() )
227 calendarDay-> header()-> setText( holidayItem-> second );
231 std::map< Wt::WDate, std::string > moon =
233 { Wt::WDate( 2018, 5, 7 ),
"Last Quarter Moon" },
234 { Wt::WDate( 2018, 5, 15 ),
"New Moon" },
235 { Wt::WDate( 2018, 5, 21 ),
"New Quarter Moon" },
236 { Wt::WDate( 2018, 5, 29 ),
"Full Moon" }
239 for(
auto calendarDay : monthView()-> dayWidgets() )
241 auto moonItem = moon.find( calendarDay-> date() );
242 if( moonItem != moon.end() )
244 calendarDay-> footer()-> setText( moonItem-> second );
252 void Wtx::Web::Calendar::Widget::setView(
int value )
254 m_toolBar-> cbView()-> setCurrentIndex( value );
255 m_stack-> setCurrentIndex( value );
258 int Wtx::Web::Calendar::Widget::view()
const 260 return m_toolBar-> cbView()-> currentIndex();
264 const Wt::WDate & Wtx::Web::Calendar::Widget::selectedDate()
const 266 return m_selectedDate;
289 Wtx::Web::Calendar::Widget::ToolBar * Wtx::Web::Calendar::Widget::toolBar()
const 294 Wtx::Web::Calendar::Widget::SideBar * Wtx::Web::Calendar::Widget::sideBar()
const 299 void Wtx::Web::Calendar::Widget::selectPrevious()
301 if( toolBar()-> cbView()-> currentText() == Wt::WString::tr(
"Wtx.Calendar.Widget.View.year" ) )
303 setSelectedDate( selectedDate().addMonths(-12) );
306 if( toolBar()-> cbView()-> currentText() == Wt::WString::tr(
"Wtx.Calendar.Widget.View.month" ) )
308 setSelectedDate( selectedDate().addMonths(-1) );
311 if( toolBar()-> cbView()-> currentText() == Wt::WString::tr(
"Wtx.Calendar.Widget.View.week" ) )
313 setSelectedDate( selectedDate().addDays(-7) );
316 if( toolBar()-> cbView()-> currentText() == Wt::WString::tr(
"Wtx.Calendar.Widget.View.day" ) )
318 setSelectedDate( selectedDate().addDays(-1) );
323 void Wtx::Web::Calendar::Widget::selectNext()
325 if( toolBar()-> cbView()-> currentText() == Wt::WString::tr(
"Wtx.Calendar.Widget.View.year" ) )
327 setSelectedDate( selectedDate().addMonths(12) );
330 if( toolBar()-> cbView()-> currentText() == Wt::WString::tr(
"Wtx.Calendar.Widget.View.month" ) )
332 setSelectedDate( selectedDate().addMonths(1) );
335 if( toolBar()-> cbView()-> currentText() == Wt::WString::tr(
"Wtx.Calendar.Widget.View.week" ) )
337 setSelectedDate( selectedDate().addDays(7) );
340 if( toolBar()-> cbView()-> currentText() == Wt::WString::tr(
"Wtx.Calendar.Widget.View.day" ) )
342 setSelectedDate( selectedDate().addDays(1) );
347 void Wtx::Web::Calendar::Widget::updateView()
350 setSelectedDate( selectedDate() );
353 void Wtx::Web::Calendar::Widget::setSelectedDate(
const Wt::WDate & date )
355 m_selectedDate = date;
356 m_sideBar-> calendar()-> browseTo( date );
357 m_sideBar-> calendar()-> select( date );
358 yearView()-> setSelectedDate( date );
359 monthView()-> setSelectedDate( date );
360 weekView()-> setSelectedDate( date );
361 dayView()-> setSelectedDate( date );
364 Wt::Signal<Wt::WDate> & Wtx::Web::Calendar::Widget::itemNew()
369 Wt::Signal<Wt::WModelIndex> & Wtx::Web::Calendar::Widget::itemClicked()
371 return m_itemClicked;
374 Wt::Signal<Wt::WModelIndex> & Wtx::Web::Calendar::Widget::itemDoubleClicked()
376 return m_itemDoubleClicked;
393 auto retVal = m_modelMaps[date];
407 std::vector<std::string> fieldList = fList;
408 fieldList.insert( fieldList.begin(),
"id" );
410 retVal = std::make_shared<Wt::WStandardItemModel>();
411 retVal-> insertColumns( 0, fieldList.size()+2 );
412 retVal-> setHeaderData( 1, Wt::Orientation::Horizontal,
"source" );
413 for(
int i=0; i< fieldList.size(); i++ )
414 retVal-> setHeaderData( i+1, Wt::Orientation::Horizontal, fieldList.at(i) );
416 for(
auto modelProvider : m_database.modelProviders() )
418 auto model = modelProvider->
getModel( date, fieldList );
420 auto _column = [=](
const Wt::cpp17::any & fieldName )
422 for(
int i=0; i< model-> columnCount(); i++ )
423 if( Wt::asString( model-> headerData( i ) ) == Wt::asString( fieldName ) )
429 int row = retVal-> rowCount();
430 retVal-> insertRows( row, model-> rowCount() );
432 for(
int i=0; i< model-> rowCount(); i++, row++ )
434 retVal-> setData( row, 0, modelProvider-> name() );
435 for(
int j=0; j< retVal-> columnCount(); j++ )
437 int column=_column( retVal-> headerData(j) );
440 retVal-> setData( row, j, model-> data( i, column ) );
446 m_modelMaps[date] = retVal;
453 Wtx::Web::Calendar::Widget::ToolBar * Wtx::Web::Calendar::Widget::toolBar()
const 458 Wtx::Web::Calendar::Widget::SideBar * Wtx::Web::Calendar::Widget::sideBar()
const