123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <template>
- <div id="main-attendees">
- <md-layout md-gutter md-row>
- <md-layout id="datepicker-column" md-column md-flex="20" md-gutter>
- <datepicker id="datepicker" :value="date" :inline="true" :highlighted="highlightedDates" @selected="getDay"></datepicker>
- <md-card id="day-info">
- <md-card-header class="group-header">
- <md-layout md-row>
- <div class="md-title day-info-title">
- <md-icon class="day-icon">today</md-icon> {{ day.day }}
- </div>
- <md-menu md-align-trigger>
- <md-button class="md-icon-button" md-menu-trigger>
- <md-icon>more_vert</md-icon>
- </md-button>
- <md-menu-content>
- <md-menu-item @click="openNotesDialog()">
- <span>edit notes</span>
- <md-icon>edit</md-icon>
- </md-menu-item>
- </md-menu-content>
- </md-menu>
- </md-layout>
- </md-card-header>
- <md-card-content>
- <div id="day-notes">{{ day.notes }}</div>
- </md-card-content>
- </md-card>
- </md-layout>
- <md-layout id="panel" md-column>
- <md-layout md-row>
- <group v-for="group in day.groups || []" :group="group" :day="day.day" new-attendee="" @updated="reload" />
- <group :add-new-group="true" :day="day.day" new-attendee="" new-group="" @updated="reload" />
- </md-layout>
- </md-layout>
- </md-layout>
- <ibt-dialog ref="dialogObj" />
- <md-dialog-prompt
- v-model="dayNotes"
- @open="dialogDayNotesOpen"
- @close="dialogDayNotesClose"
- :md-title="noteDialog.title"
- :md-ok-text="noteDialog.ok"
- :md-cancel-text="noteDialog.cancel"
- ref="dialogDayNotes">
- </md-dialog-prompt>
- </div>
- </template>
- <script>
- import Datepicker from 'vuejs-datepicker';
- import Group from './Group';
- import IbtDialog from './IbtDialog.vue';
- export default {
- data() {
- return {
- date: null, // a Date object representing the selected date
- day: {},
- daysSummary: {},
- dayNotes: '',
- noteDialog: {title: 'Day notes', ok: 'ok', cancel: 'cancel'}
- }
- },
- computed: {
- highlightedDates() {
- var ds = this.daysSummary.days || [];
- var datesWithGroups = [];
- for (var i=0; i < ds.length; i++) {
- var [year, month, day] = ds[i].day.split('-');
- year = parseInt(year);
- month = parseInt(month) - 1;
- day = parseInt(day);
- if (isNaN(year) || isNaN(month) || isNaN(day)) {
- continue;
- }
- datesWithGroups.push(new Date(year, month, day));
- }
- return {
- dates: datesWithGroups
- };
- }
- },
- beforeCreate: function() {
- this.daysUrl = this.$resource('days{/day}');
- },
- mounted: function() {
- var [year, month, day] = (this.$route.params.day || '').split('-');
- year = parseInt(year);
- month = parseInt(month) - 1;
- day = parseInt(day);
- if (!isNaN(year) && !isNaN(month) && !isNaN(day)) {
- this.date = new Date(year, month, day);
- }
- if (!(this.date && !isNaN(this.date.getTime()))) {
- this.date = new Date();
- }
- this.reload();
- },
- methods: {
- reload() {
- var ym = this.dateToString(this.date, true);
- this.getSummary({start: ym, end: ym});
- this.getDay();
- },
- dateToString(date, excludeDay) {
- var year = '' + date.getFullYear();
- var month = '' + (date.getMonth() + 1);
- month = '00'.substring(0, 2 - month.length) + month;
- var ym = year + '-' + month;
- if (excludeDay) {
- return ym;
- }
- var day = '' + (date.getDate());
- day = '00'.substring(0, 2 - day.length) + day;
- return ym + '-' + day;
- },
- getSummary(params) {
- if (!params) {
- params = {};
- }
- params['summary'] = true;
- this.daysUrl.query(params).then((response) => {
- return response.json();
- }, (response) => {
- this.$refs.dialogObj.show({text: 'unable to get the monthly summary'});
- }).then((json) => {
- this.daysSummary = json;
- });
- },
- getDay(day) {
- if (day instanceof Date) {
- this.date = day;
- day = this.dateToString(day);
- } else if (this.date && this.date instanceof Date) {
- day = this.dateToString(this.date);
- } else {
- var today = new Date();
- day = this.dateToString(today);
- this.date = today;
- }
- this.$router.push('/day/' + day);
- this.daysUrl.get({day: day}).then((response) => {
- return response.json();
- }, (response) => {
- this.$refs.dialogObj.show({text: 'unable to get information about this day'});
- }).then((dayData) => {
- if (!(dayData && dayData.day)) {
- dayData.day = day;
- }
- this.day = dayData;
- });
- },
- openNotesDialog() {
- this.$refs.dialogDayNotes.open();
- },
- dialogDayNotesOpen() {
- this.dayNotes = this.day.notes || '';
- },
- dialogDayNotesClose(type) {
- if (type != 'ok' || !this.day) {
- return;
- }
- var data = {day: this.day.day, notes: this.dayNotes};
- this.daysUrl.update(data).then((response) => {
- return response.json();
- }, (response) => {
- this.$refs.dialogObj.show({text: 'unable to edit day notes'});
- }).then((json) => {
- this.day.notes = json.notes;
- });
- }
- },
- components: {
- Datepicker, Group, IbtDialog
- }
- }
- </script>
- <style>
- #main-attendees {
- font-family: 'Avenir', Helvetica, Arial, sans-serif;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- color: #2c3e50;
- margin-top: 0px;
- }
- #datepicker-column {
- min-width: 320px;
- }
- #datepicker {
- padding: 10px;
- }
- #panel .md-layout {
- flex: initial;
- }
- #day-info {
- margin: 10px;
- width: 300px;
- min-height: 200px;
- }
- .day-info-title {
- flex: 1;
- }
- #day-notes {
- padding: 10px;
- color: rgba(0, 0, 0, 0.54);
- }
- .day-icon {
- vertical-align: text-top;
- }
- </style>
|