App.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <div id="main-attendees">
  3. <md-layout md-gutter md-row>
  4. <md-layout id="datepicker-column" md-column md-flex="20" md-gutter>
  5. <datepicker id="datepicker" :value="date" :inline="true" :highlighted="highlightedDates" @selected="getDay"></datepicker>
  6. <md-card id="day-info">
  7. <md-card-header class="group-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. this.reload();
  98. },
  99. methods: {
  100. reload() {
  101. var ym = this.dateToString(this.date, true);
  102. this.getSummary({start: ym, end: ym});
  103. this.getDay();
  104. },
  105. dateToString(date, excludeDay) {
  106. var year = '' + date.getFullYear();
  107. var month = '' + (date.getMonth() + 1);
  108. month = '00'.substring(0, 2 - month.length) + month;
  109. var ym = year + '-' + month;
  110. if (excludeDay) {
  111. return ym;
  112. }
  113. var day = '' + (date.getDate());
  114. day = '00'.substring(0, 2 - day.length) + day;
  115. return ym + '-' + day;
  116. },
  117. getSummary(params) {
  118. if (!params) {
  119. params = {};
  120. }
  121. params['summary'] = true;
  122. this.daysUrl.query(params).then((response) => {
  123. return response.json();
  124. }, (response) => {
  125. this.$refs.dialogObj.show({text: 'unable to get the monthly summary'});
  126. }).then((json) => {
  127. this.daysSummary = json;
  128. });
  129. },
  130. getDay(day) {
  131. if (day instanceof Date) {
  132. this.date = day;
  133. day = this.dateToString(day);
  134. } else if (this.date && this.date instanceof Date) {
  135. day = this.dateToString(this.date);
  136. } else {
  137. var today = new Date();
  138. day = this.dateToString(today);
  139. this.date = today;
  140. }
  141. this.$router.push('/day/' + day);
  142. this.daysUrl.get({day: day}).then((response) => {
  143. return response.json();
  144. }, (response) => {
  145. this.$refs.dialogObj.show({text: 'unable to get information about this day'});
  146. }).then((dayData) => {
  147. if (!(dayData && dayData.day)) {
  148. dayData.day = day;
  149. }
  150. this.day = dayData;
  151. });
  152. },
  153. openNotesDialog() {
  154. this.$refs.dialogDayNotes.open();
  155. },
  156. dialogDayNotesOpen() {
  157. this.dayNotes = this.day.notes || '';
  158. },
  159. dialogDayNotesClose(type) {
  160. if (type != 'ok' || !this.day) {
  161. return;
  162. }
  163. var data = {day: this.day.day, notes: this.dayNotes};
  164. this.daysUrl.update(data).then((response) => {
  165. return response.json();
  166. }, (response) => {
  167. this.$refs.dialogObj.show({text: 'unable to edit day notes'});
  168. }).then((json) => {
  169. this.day.notes = json.notes;
  170. this.reload();
  171. });
  172. }
  173. },
  174. components: { Datepicker, Group, IbtDialog, VueMarkdown }
  175. }
  176. </script>
  177. <style>
  178. #main-attendees {
  179. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  180. -webkit-font-smoothing: antialiased;
  181. -moz-osx-font-smoothing: grayscale;
  182. color: #2c3e50;
  183. margin-top: 0px;
  184. }
  185. #datepicker-column {
  186. min-width: 320px;
  187. }
  188. #datepicker {
  189. padding: 10px;
  190. }
  191. #panel .md-layout {
  192. flex: initial;
  193. }
  194. #day-info {
  195. margin: 10px;
  196. width: 300px;
  197. min-height: 200px;
  198. }
  199. .day-info-title {
  200. flex: 1;
  201. }
  202. #day-notes {
  203. color: rgba(0, 0, 0, 0.54);
  204. }
  205. .day-icon {
  206. vertical-align: text-top;
  207. }
  208. </style>