App.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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">{{ day.notes }}</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. export default {
  54. data() {
  55. return {
  56. date: null, // a Date object representing the selected date
  57. day: {},
  58. daysSummary: {},
  59. dayNotes: '',
  60. noteDialog: {title: 'Day notes', ok: 'ok', cancel: 'cancel'}
  61. }
  62. },
  63. computed: {
  64. highlightedDates() {
  65. var ds = this.daysSummary.days || [];
  66. var datesWithGroups = [];
  67. for (var i=0; i < ds.length; i++) {
  68. var [year, month, day] = ds[i].day.split('-');
  69. year = parseInt(year);
  70. month = parseInt(month) - 1;
  71. day = parseInt(day);
  72. if (isNaN(year) || isNaN(month) || isNaN(day)) {
  73. continue;
  74. }
  75. datesWithGroups.push(new Date(year, month, day));
  76. }
  77. return {
  78. dates: datesWithGroups
  79. };
  80. }
  81. },
  82. beforeCreate: function() {
  83. this.daysUrl = this.$resource('days{/day}');
  84. },
  85. mounted: function() {
  86. var [year, month, day] = (this.$route.params.day || '').split('-');
  87. year = parseInt(year);
  88. month = parseInt(month) - 1;
  89. day = parseInt(day);
  90. if (!isNaN(year) && !isNaN(month) && !isNaN(day)) {
  91. this.date = new Date(year, month, day);
  92. }
  93. if (!(this.date && !isNaN(this.date.getTime()))) {
  94. this.date = new Date();
  95. }
  96. this.reload();
  97. },
  98. methods: {
  99. reload() {
  100. var ym = this.dateToString(this.date, true);
  101. this.getSummary({start: ym, end: ym});
  102. this.getDay();
  103. },
  104. dateToString(date, excludeDay) {
  105. var year = '' + date.getFullYear();
  106. var month = '' + (date.getMonth() + 1);
  107. month = '00'.substring(0, 2 - month.length) + month;
  108. var ym = year + '-' + month;
  109. if (excludeDay) {
  110. return ym;
  111. }
  112. var day = '' + (date.getDate());
  113. day = '00'.substring(0, 2 - day.length) + day;
  114. return ym + '-' + day;
  115. },
  116. getSummary(params) {
  117. if (!params) {
  118. params = {};
  119. }
  120. params['summary'] = true;
  121. this.daysUrl.query(params).then((response) => {
  122. return response.json();
  123. }, (response) => {
  124. this.$refs.dialogObj.show({text: 'unable to get the monthly summary'});
  125. }).then((json) => {
  126. this.daysSummary = json;
  127. });
  128. },
  129. getDay(day) {
  130. if (day instanceof Date) {
  131. this.date = day;
  132. day = this.dateToString(day);
  133. } else if (this.date && this.date instanceof Date) {
  134. day = this.dateToString(this.date);
  135. } else {
  136. var today = new Date();
  137. day = this.dateToString(today);
  138. this.date = today;
  139. }
  140. this.$router.push('/day/' + day);
  141. this.daysUrl.get({day: day}).then((response) => {
  142. return response.json();
  143. }, (response) => {
  144. this.$refs.dialogObj.show({text: 'unable to get information about this day'});
  145. }).then((dayData) => {
  146. if (!(dayData && dayData.day)) {
  147. dayData.day = day;
  148. }
  149. this.day = dayData;
  150. });
  151. },
  152. openNotesDialog() {
  153. this.$refs.dialogDayNotes.open();
  154. },
  155. dialogDayNotesOpen() {
  156. this.dayNotes = this.day.notes || '';
  157. },
  158. dialogDayNotesClose(type) {
  159. if (type != 'ok' || !this.day) {
  160. return;
  161. }
  162. var data = {day: this.day.day, notes: this.dayNotes};
  163. this.daysUrl.update(data).then((response) => {
  164. return response.json();
  165. }, (response) => {
  166. this.$refs.dialogObj.show({text: 'unable to edit day notes'});
  167. }).then((json) => {
  168. this.day.notes = json.notes;
  169. });
  170. }
  171. },
  172. components: {
  173. Datepicker, Group, IbtDialog
  174. }
  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. padding: 10px;
  204. color: rgba(0, 0, 0, 0.54);
  205. }
  206. .day-icon {
  207. vertical-align: text-top;
  208. }
  209. </style>