App.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div id="main-attendees">
  3. <md-layout md-gutter md-row>
  4. <md-layout md-column md-flex="20" md-gutter>
  5. <datepicker id="datepicker" :value="date" :inline="true" :highlighted="highlightedDates" @selected="getDay"></datepicker>
  6. </md-layout>
  7. <md-layout id="panel" md-column>
  8. <md-layout md-row>
  9. <group v-for="group in day.groups || []" :group="group" :day="day.day" new-attendee="" @updated="reload" />
  10. <group :add-new-group="true" :day="day.day" new-attendee="" new-group="" @updated="reload" />
  11. </md-layout>
  12. </md-layout>
  13. </md-layout>
  14. <ibt-dialog ref="dialogObj" />
  15. </div>
  16. </template>
  17. <script>
  18. import Datepicker from 'vuejs-datepicker';
  19. import Group from './Group';
  20. import IbtDialog from './IbtDialog.vue';
  21. export default {
  22. data() {
  23. return {
  24. date: null, // a Date object representing the selected date
  25. day: {},
  26. daysSummary: {}
  27. }
  28. },
  29. computed: {
  30. highlightedDates() {
  31. var ds = this.daysSummary.days || [];
  32. var datesWithGroups = [];
  33. for (var i=0; i < ds.length; i++) {
  34. var [year, month, day] = ds[i].day.split('-');
  35. year = parseInt(year);
  36. month = parseInt(month) - 1;
  37. day = parseInt(day);
  38. if (isNaN(year) || isNaN(month) || isNaN(day)) {
  39. continue;
  40. }
  41. datesWithGroups.push(new Date(year, month, day));
  42. }
  43. return {
  44. dates: datesWithGroups
  45. };
  46. }
  47. },
  48. beforeCreate: function() {
  49. this.daysUrl = this.$resource('days{/day}');
  50. this.attendeesUrl = this.$resource('attendees{/id}');
  51. this.currentUserUrl = this.$resource('users/current');
  52. this.loginUrl = this.$resource('login');
  53. this.logoutUrl = this.$resource('logout');
  54. },
  55. mounted: function() {
  56. var [year, month, day] = (this.$route.params.day || '').split('-');
  57. year = parseInt(year);
  58. month = parseInt(month) - 1;
  59. day = parseInt(day);
  60. if (!isNaN(year) && !isNaN(month) && !isNaN(day)) {
  61. this.date = new Date(year, month, day);
  62. }
  63. if (!(this.date && !isNaN(this.date.getTime()))) {
  64. this.date = new Date();
  65. }
  66. this.reload();
  67. },
  68. methods: {
  69. reload() {
  70. var ym = this.dateToString(this.date, true);
  71. this.getSummary({start: ym, end: ym});
  72. this.getDay();
  73. },
  74. dateToString(date, excludeDay) {
  75. var year = '' + date.getFullYear();
  76. var month = '' + (date.getMonth() + 1);
  77. month = '00'.substring(0, 2 - month.length) + month;
  78. var ym = year + '-' + month;
  79. if (excludeDay) {
  80. return ym;
  81. }
  82. var day = '' + (date.getDate());
  83. day = '00'.substring(0, 2 - day.length) + day;
  84. return ym + '-' + day;
  85. },
  86. getSummary(params) {
  87. if (!params) {
  88. params = {};
  89. }
  90. params['summary'] = true;
  91. this.daysUrl.query(params).then((response) => {
  92. return response.json();
  93. }, (response) => {
  94. this.$refs.dialogObj.show({text: 'unable to get the monthly summary'});
  95. }).then((json) => {
  96. this.daysSummary = json;
  97. });
  98. },
  99. getDay(day) {
  100. if (day instanceof Date) {
  101. this.date = day;
  102. day = this.dateToString(day);
  103. } else if (this.date && this.date instanceof Date) {
  104. day = this.dateToString(this.date);
  105. } else {
  106. var today = new Date();
  107. day = this.dateToString(today);
  108. this.date = today;
  109. }
  110. this.$router.push('/day/' + day);
  111. this.daysUrl.get({day: day}).then((response) => {
  112. return response.json();
  113. }, (response) => {
  114. this.$refs.dialogObj.show({text: 'unable to get information about this day'});
  115. }).then((dayData) => {
  116. if (!(dayData && dayData.day)) {
  117. dayData.day = day;
  118. }
  119. this.day = dayData;
  120. });
  121. }
  122. },
  123. components: {
  124. Datepicker, Group, IbtDialog
  125. }
  126. }
  127. </script>
  128. <style>
  129. #main-attendees {
  130. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  131. -webkit-font-smoothing: antialiased;
  132. -moz-osx-font-smoothing: grayscale;
  133. color: #2c3e50;
  134. margin-top: 0px;
  135. }
  136. #datepicker {
  137. padding: 10px;
  138. }
  139. #panel .md-layout {
  140. flex: initial;
  141. }
  142. #toolbar-title {
  143. flex: 1;
  144. }
  145. .login-input {
  146. width: 200px;
  147. margin: 0px 0px 0px;
  148. padding-top: 0px;
  149. padding-left: 4px;
  150. min-height: 24px;
  151. line-height: 0px;
  152. margin-right: 20px;
  153. background-color: white;
  154. }
  155. </style>