App.vue 4.8 KB

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