App.vue 4.2 KB

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