App.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. this.daysInfoUrl = this.$resource('days{/day}/info');
  86. },
  87. mounted: function() {
  88. var [year, month, day] = (this.$route.params.day || '').split('-');
  89. year = parseInt(year);
  90. month = parseInt(month) - 1;
  91. day = parseInt(day);
  92. if (!isNaN(year) && !isNaN(month) && !isNaN(day)) {
  93. this.date = new Date(year, month, day);
  94. }
  95. if (!(this.date && !isNaN(this.date.getTime()))) {
  96. this.date = new Date();
  97. }
  98. $('div.calendar span.prev').on('click', this.changeMonth);
  99. $('div.calendar span.next').on('click', this.changeMonth);
  100. $('div.calendar span.month').on('click', this.changeMonth);
  101. this.reload();
  102. },
  103. methods: {
  104. reload() {
  105. var ym = this.dateToString(this.date, true);
  106. this.getSummary({start: ym, end: ym});
  107. this.getDay();
  108. },
  109. changeMonth() {
  110. var day = new Date();
  111. day.setTime(this.$refs.datepicker.currDate);
  112. var ym = this.dateToString(day, true);
  113. this.getSummary({start: ym, end: ym});
  114. this.getDay(day);
  115. },
  116. dateToString(date, excludeDay) {
  117. var year = '' + date.getFullYear();
  118. var month = '' + (date.getMonth() + 1);
  119. month = '00'.substring(0, 2 - month.length) + month;
  120. var ym = year + '-' + month;
  121. if (excludeDay) {
  122. return ym;
  123. }
  124. var day = '' + (date.getDate());
  125. day = '00'.substring(0, 2 - day.length) + day;
  126. return ym + '-' + day;
  127. },
  128. getSummary(params) {
  129. if (!params) {
  130. params = {};
  131. }
  132. params['summary'] = true;
  133. this.daysUrl.query(params).then((response) => {
  134. return response.json();
  135. }, (response) => {
  136. this.$refs.dialogObj.show({text: 'unable to get the monthly summary'});
  137. }).then((json) => {
  138. this.daysSummary = json;
  139. });
  140. },
  141. getDay(day) {
  142. if (day instanceof Date) {
  143. this.date = day;
  144. day = this.dateToString(day);
  145. } else if (this.date && this.date instanceof Date) {
  146. day = this.dateToString(this.date);
  147. } else {
  148. var today = new Date();
  149. day = this.dateToString(today);
  150. this.date = today;
  151. }
  152. this.$router.push('/day/' + day);
  153. this.daysUrl.get({day: day}).then((response) => {
  154. return response.json();
  155. }, (response) => {
  156. this.$refs.dialogObj.show({text: 'unable to get information about this day'});
  157. }).then((dayData) => {
  158. if (!(dayData && dayData.day)) {
  159. dayData.day = day;
  160. }
  161. this.day = dayData;
  162. });
  163. },
  164. openNotesDialog() {
  165. this.$refs.dialogDayNotes.open();
  166. },
  167. dialogDayNotesOpen() {
  168. this.dayNotes = this.day.notes || '';
  169. },
  170. dialogDayNotesClose(type) {
  171. if (type != 'ok' || !this.day) {
  172. return;
  173. }
  174. var data = {day: this.day.day, notes: this.dayNotes};
  175. this.daysInfoUrl.update({day: this.day.day}, data).then((response) => {
  176. return response.json();
  177. }, (response) => {
  178. this.$refs.dialogObj.show({text: 'unable to edit day notes'});
  179. }).then((json) => {
  180. this.day.notes = json.notes;
  181. this.reload();
  182. });
  183. }
  184. },
  185. components: { Datepicker, Group, IbtDialog, VueMarkdown }
  186. }
  187. </script>
  188. <style>
  189. #main-attendees {
  190. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  191. -webkit-font-smoothing: antialiased;
  192. -moz-osx-font-smoothing: grayscale;
  193. color: #2c3e50;
  194. margin-top: 0px;
  195. }
  196. #datepicker-column {
  197. min-width: 320px;
  198. }
  199. @media screen and (min-width: 945px) {
  200. #datepicker-column {
  201. flex-direction: column;
  202. }
  203. }
  204. .datepicker {
  205. padding: 10px;
  206. }
  207. #panel .md-layout {
  208. flex: initial;
  209. }
  210. #day-info {
  211. margin: 10px;
  212. width: 300px;
  213. min-height: 200px;
  214. }
  215. .day-info-title {
  216. flex: 1;
  217. }
  218. .day-info-header {
  219. background-color: #f8bbd0;
  220. }
  221. .calendar > header > span {
  222. background-color: #f8bbd0;
  223. }
  224. .calendar > header > span:hover {
  225. background-color: #f06292 !important;
  226. }
  227. #day-notes {
  228. color: rgba(0, 0, 0, 0.54);
  229. }
  230. .day-icon {
  231. vertical-align: text-top;
  232. }
  233. </style>