App.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <div id="main-attendees">
  3. <md-layout md-gutter md-row>
  4. <md-layout id="datepicker-column" md-flex="20" md-flex-small="100" md-gutter>
  5. <datepicker id="datepicker" ref="datepicker" :value="date" :inline="true" :highlighted="highlightedDates" :monday-first="true" @selected="getDay"></datepicker>
  6. <md-card id="day-info">
  7. <md-card-header class="day-info-header">
  8. <md-layout md-row>
  9. <div class="md-title day-info-title">
  10. <md-icon class="day-icon">today</md-icon>&nbsp;{{ day.day }}
  11. </div>
  12. <md-menu md-align-trigger>
  13. <md-button class="md-icon-button" md-menu-trigger>
  14. <md-icon>more_vert</md-icon>
  15. </md-button>
  16. <md-menu-content>
  17. <md-menu-item @click="openNotesDialog()">
  18. <span>edit notes</span>
  19. <md-icon>edit</md-icon>
  20. </md-menu-item>
  21. </md-menu-content>
  22. </md-menu>
  23. </md-layout>
  24. </md-card-header>
  25. <md-card-content>
  26. <div id="day-notes"><vue-markdown :source="day.notes"></vue-markdown></div>
  27. </md-card-content>
  28. </md-card>
  29. </md-layout>
  30. <md-layout id="panel" md-column>
  31. <md-layout md-row>
  32. <group v-for="group in day.groups || []" :group="group" :day="day.day" new-attendee="" @updated="reload" />
  33. <group :add-new-group="true" :day="day.day" new-attendee="" new-group="" @updated="reload" />
  34. </md-layout>
  35. </md-layout>
  36. </md-layout>
  37. <ibt-dialog ref="dialogObj" />
  38. <md-dialog-prompt
  39. v-model="dayNotes"
  40. @open="dialogDayNotesOpen"
  41. @close="dialogDayNotesClose"
  42. :md-title="noteDialog.title"
  43. :md-ok-text="noteDialog.ok"
  44. :md-cancel-text="noteDialog.cancel"
  45. ref="dialogDayNotes">
  46. </md-dialog-prompt>
  47. </div>
  48. </template>
  49. <script>
  50. import Datepicker from 'vuejs-datepicker';
  51. import Group from './Group';
  52. import IbtDialog from './IbtDialog.vue';
  53. import VueMarkdown from 'vue-markdown';
  54. export default {
  55. data() {
  56. return {
  57. date: null, // a Date object representing the selected date
  58. day: {},
  59. daysSummary: {},
  60. dayNotes: '',
  61. noteDialog: {title: 'Day notes', ok: 'ok', cancel: 'cancel'}
  62. }
  63. },
  64. computed: {
  65. highlightedDates() {
  66. var ds = this.daysSummary.days || [];
  67. var datesWithGroups = [];
  68. for (var i=0; i < ds.length; i++) {
  69. var [year, month, day] = ds[i].day.split('-');
  70. year = parseInt(year);
  71. month = parseInt(month) - 1;
  72. day = parseInt(day);
  73. if (isNaN(year) || isNaN(month) || isNaN(day)) {
  74. continue;
  75. }
  76. datesWithGroups.push(new Date(year, month, day));
  77. }
  78. return {
  79. dates: datesWithGroups
  80. };
  81. }
  82. },
  83. beforeCreate: function() {
  84. this.daysUrl = this.$resource('days{/day}');
  85. },
  86. mounted: function() {
  87. var [year, month, day] = (this.$route.params.day || '').split('-');
  88. year = parseInt(year);
  89. month = parseInt(month) - 1;
  90. day = parseInt(day);
  91. if (!isNaN(year) && !isNaN(month) && !isNaN(day)) {
  92. this.date = new Date(year, month, day);
  93. }
  94. if (!(this.date && !isNaN(this.date.getTime()))) {
  95. this.date = new Date();
  96. }
  97. $('div.calendar span.prev').on('click', this.changeMonth);
  98. $('div.calendar span.next').on('click', this.changeMonth);
  99. $('div.calendar span.month').on('click', this.changeMonth);
  100. this.reload();
  101. },
  102. methods: {
  103. reload() {
  104. var ym = this.dateToString(this.date, true);
  105. this.getSummary({start: ym, end: ym});
  106. this.getDay();
  107. },
  108. changeMonth() {
  109. var day = new Date();
  110. day.setTime(this.$refs.datepicker.currDate);
  111. var ym = this.dateToString(day, true);
  112. this.getSummary({start: ym, end: ym});
  113. this.getDay(day);
  114. },
  115. dateToString(date, excludeDay) {
  116. var year = '' + date.getFullYear();
  117. var month = '' + (date.getMonth() + 1);
  118. month = '00'.substring(0, 2 - month.length) + month;
  119. var ym = year + '-' + month;
  120. if (excludeDay) {
  121. return ym;
  122. }
  123. var day = '' + (date.getDate());
  124. day = '00'.substring(0, 2 - day.length) + day;
  125. return ym + '-' + day;
  126. },
  127. getSummary(params) {
  128. if (!params) {
  129. params = {};
  130. }
  131. params['summary'] = true;
  132. this.daysUrl.query(params).then((response) => {
  133. return response.json();
  134. }, (response) => {
  135. this.$refs.dialogObj.show({text: 'unable to get the monthly summary'});
  136. }).then((json) => {
  137. this.daysSummary = json;
  138. });
  139. },
  140. getDay(day) {
  141. if (day instanceof Date) {
  142. this.date = day;
  143. day = this.dateToString(day);
  144. } else if (this.date && this.date instanceof Date) {
  145. day = this.dateToString(this.date);
  146. } else {
  147. var today = new Date();
  148. day = this.dateToString(today);
  149. this.date = today;
  150. }
  151. this.$router.push('/day/' + day);
  152. this.daysUrl.get({day: day}).then((response) => {
  153. return response.json();
  154. }, (response) => {
  155. this.$refs.dialogObj.show({text: 'unable to get information about this day'});
  156. }).then((dayData) => {
  157. if (!(dayData && dayData.day)) {
  158. dayData.day = day;
  159. }
  160. this.day = dayData;
  161. });
  162. },
  163. openNotesDialog() {
  164. this.$refs.dialogDayNotes.open();
  165. },
  166. dialogDayNotesOpen() {
  167. this.dayNotes = this.day.notes || '';
  168. },
  169. dialogDayNotesClose(type) {
  170. if (type != 'ok' || !this.day) {
  171. return;
  172. }
  173. var data = {day: this.day.day, notes: this.dayNotes};
  174. this.daysUrl.update(data).then((response) => {
  175. return response.json();
  176. }, (response) => {
  177. this.$refs.dialogObj.show({text: 'unable to edit day notes'});
  178. }).then((json) => {
  179. this.day.notes = json.notes;
  180. this.reload();
  181. });
  182. }
  183. },
  184. components: { Datepicker, Group, IbtDialog, VueMarkdown }
  185. }
  186. </script>
  187. <style>
  188. #main-attendees {
  189. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  190. -webkit-font-smoothing: antialiased;
  191. -moz-osx-font-smoothing: grayscale;
  192. color: #2c3e50;
  193. margin-top: 0px;
  194. }
  195. #datepicker-column {
  196. min-width: 320px;
  197. }
  198. @media screen and (min-width: 945px) {
  199. #datepicker-column {
  200. flex-direction: column;
  201. }
  202. }
  203. .datepicker {
  204. padding: 10px;
  205. }
  206. #panel .md-layout {
  207. flex: initial;
  208. }
  209. #day-info {
  210. margin: 10px;
  211. width: 300px;
  212. min-height: 200px;
  213. }
  214. .day-info-title {
  215. flex: 1;
  216. }
  217. .calendar > header > span {
  218. background-color: #f8bbd0;
  219. }
  220. .calendar > header > span:hover {
  221. background-color: #f06292 !important;
  222. }
  223. #day-notes {
  224. color: rgba(0, 0, 0, 0.54);
  225. }
  226. .day-icon {
  227. vertical-align: text-top;
  228. }
  229. </style>