From 44305d8778c852e62563a865f183381fab9087eb Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Thu, 24 Oct 2019 23:30:18 +0200 Subject: [PATCH 1/4] - Delete Event with ask confirmation - Fix dateStart only 1 view if is the same day - Sending a message from the Event Page: to a user or to a "Event" - Add button "Ask Info" - Starting view msg into the messagepopup component --- .../CEventsCalendar/CEventsCalendar.ts | 93 ++++++- .../CEventsCalendar/CEventsCalendar.vue | 115 +++++---- src/components/Header/Header.vue | 2 - .../toolbar/messagePopover/messagePopover.ts | 42 ++-- .../toolbar/messagePopover/messagePopover.vue | 48 ++-- src/model/Calendar.ts | 29 +++ src/model/UserStore.ts | 2 + src/statics/i18n.js | 58 ++++- src/store/Modules/GlobalStore.ts | 12 +- .../Modules/Store/calendar/CalendarStore.ts | 11 +- src/store/Modules/UserStore.ts | 38 ++- src/store/Modules/lists.ts | 1 + src/store/Modules/tools.ts | 237 +++++++++++++----- 13 files changed, 508 insertions(+), 180 deletions(-) diff --git a/src/components/CEventsCalendar/CEventsCalendar.ts b/src/components/CEventsCalendar/CEventsCalendar.ts index fee862c..9cf1aa3 100644 --- a/src/components/CEventsCalendar/CEventsCalendar.ts +++ b/src/components/CEventsCalendar/CEventsCalendar.ts @@ -22,7 +22,7 @@ import QDateTimeScroller from '@quasar/quasar-app-extension-qscroller/src/compon import { CTodo } from '@src/components/todos/CTodo' import { SingleProject } from '@src/components/projects/SingleProject' import { IEvents } from '@src/model' -import { IBookedEvent, IBookedEventPage, EState } from '@src/model/Calendar' +import { IBookedEvent, IBookedEventPage, IMessagePage, EState, IMessage, IDest, IOrigin } from '@src/model/Calendar' import { costanti } from '@src/store/Modules/costanti' import router from '@router' import { static_data } from '@src/db/static_data' @@ -58,6 +58,17 @@ export default class CEventsCalendar extends Vue { modified: false } + public formAskForDefault: IMessage = { + dest: { + idapp: process.env.APP_ID, + username: '' + }, + origin: { + userId: '' + }, + message: '' + } + public mioalert = false public dateFormatter: any = '' @@ -78,10 +89,16 @@ export default class CEventsCalendar extends Vue { bookedevent: null, state: EState.None } + public askInfopage: IMessagePage = { + show: false, + msg: null, + state: EState.None + } public contextDay = null public eventForm: IEvents = { ...this.formDefault } public bookEventForm = { ...this.formbookEventDefault } + public askInfoForm: IMessage = { ...this.formAskForDefault } public displayEvent = false public myevent = null // public events = [] @@ -355,7 +372,6 @@ export default class CEventsCalendar extends Vue { return this } - public $refs: { calendar: any } @@ -434,6 +450,7 @@ export default class CEventsCalendar extends Vue { this.myevent = eventparam this.bookEventForm.msgbooking = '' this.bookEventForm.numpeople = 1 + this.bookEventForm.booked = true this.bookEventpage.state = EState.Creating this.displayEvent = false @@ -441,6 +458,28 @@ export default class CEventsCalendar extends Vue { } } + public askForInfoEventMenu(eventparam) { + if (!UserStore.state.isLogged || !UserStore.state.verified_email) { + // Visu right Toolbar to make SignIn + GlobalStore.state.RightDrawerOpen = true + // this.$router.push('/signin') + } else { + console.log('askForInfoEventMenu') + this.askInfoForm = { ...this.formAskForDefault } + + this.myevent = eventparam + + this.askInfoForm = { + message: '' + } + + this.askInfopage.state = EState.Creating + + this.displayEvent = false + this.askInfopage.show = true // show dialog + } + } + public clEvent(event: IEvents) { return (this.isAlreadyBooked(event) ? 'text-left bg-light-green-1' : 'text-left') } @@ -460,10 +499,7 @@ export default class CEventsCalendar extends Vue { } public deleteEvent(eventparam) { - const index = this.findEventIndex(eventparam) - if (index >= 0) { - CalendarStore.state.eventlist.splice(index, 1) - } + tools.CancelEvent(this, eventparam) } public findEventIndex(eventparam) { @@ -514,7 +550,7 @@ export default class CEventsCalendar extends Vue { const mydatatosave = { id: myrec._id, - table: 'myevents', + table: tools.TABEVENTS, fieldsvalue: myrec } @@ -557,7 +593,7 @@ export default class CEventsCalendar extends Vue { // ++Save into the Database const mydatatosave = { id: data._id, - table: 'myevents', + table: tools.TABEVENTS, fieldsvalue: data } @@ -565,7 +601,7 @@ export default class CEventsCalendar extends Vue { this.UpdateDbByFields(data, true) } else { const mydataadd = { - table: 'myevents', + table: tools.TABEVENTS, data } @@ -623,7 +659,36 @@ export default class CEventsCalendar extends Vue { } public sendMsg(myevent: IEvents) { - // .. + const self = this + this.askInfopage.show = false + + const data: IMessage = { + idapp: process.env.APP_ID, + origin: { + userId: UserStore.state.userId, + page: '', + event_id: myevent._id, + infoevent: tools.gettextevent(this, myevent) + }, + dest: { + idapp: process.env.APP_ID, + username: myevent.teacher + }, + read: false, + deleted: false, + message: this.askInfoForm.message, + datemsg: tools.getDateNow() + } + + this.SendMsgEvent(data).then((ris) => { + self.contextDay = null + if (ris) + tools.showPositiveNotif(self.$q, self.$t('cal.sendmsg_sent')) + else + tools.showNegativeNotif(self.$q, self.$t('cal.sendmsg_error')) + }) + + } public saveBookEvent(myevent: IEvents) { @@ -772,6 +837,10 @@ export default class CEventsCalendar extends Vue { return await CalendarStore.actions.BookEvent(eventparam) } + public async SendMsgEvent(param: IMessage) { + return await UserStore.actions.SendMsgEvent(param) + } + public isAlreadyBooked(eventparam: IEvents) { return CalendarStore.getters.findEventBooked(eventparam, true) } @@ -961,6 +1030,8 @@ export default class CEventsCalendar extends Vue { // check if event is in the past const datenow = tools.addDays(tools.getDateNow(), -1) - return (myevent.dateTimeEnd >= datenow) + // console.log('datenow', datenow, 'end', myevent.dateTimeEnd) + + return (new Date(myevent.dateTimeEnd) >= datenow) } } diff --git a/src/components/CEventsCalendar/CEventsCalendar.vue b/src/components/CEventsCalendar/CEventsCalendar.vue index 463ee3b..84e40f4 100644 --- a/src/components/CEventsCalendar/CEventsCalendar.vue +++ b/src/components/CEventsCalendar/CEventsCalendar.vue @@ -74,23 +74,9 @@
- {{$t('cal.when')}}: - {{ tools.getstrDate(myevent.dateTimeStart)}} - {{ tools.getstrDate(myevent.dateTimeEnd)}} - - - {{$t('cal.hours')}}: - {{ myevent.infoextra }} - - - - - - {{$t('cal.hours')}}: - {{$t('cal.starttime')}} {{ tools.getstrTime(myevent.dateTimeStart) }} - {{ $t('cal.endtime')}}: {{ tools.getstrTime(myevent.dateTimeEnd) }} - - - + {{$t('cal.when')}}: + +

- {{$t('cal.when')}}: - {{func_tools.getDateStr(myevent.dateTimeStart)}} - - {{func_tools.getDateStr(myevent.dateTimeEnd)}}
- - {{$t('cal.hours')}}: - {{ myevent.infoextra }} - - - - - - {{$t('cal.hours')}}: - {{$t('cal.starttime')}} {{ tools.getstrTime(myevent.dateTimeStart) }} - - - {{$t('cal.endtime')}} - - - - {{ tools.getstrTime(myevent.dateTimeEnd) }} - - - - + {{$t('cal.when')}}: + +
@@ -369,7 +335,7 @@ - @@ -380,6 +346,53 @@ + + + + + {{$t('cal.booking')}} + + + + + + + +
+ + + {{myevent.title}} + +
+ {{$t('cal.when')}}: + + +
+
+ + + + + + + +
+
+
+ + + + +
+
+ @@ -547,17 +560,7 @@

- -
- {{func_tools.getDateStr(event.dateTimeStart)}} - {{ event.infoextra }} -
-
-
- {{tools.getstrDateTime(event.dateTimeStart)}} - - {{tools.getstrDateTime(event.dateTimeEnd)}} -
-
+
@@ -649,12 +652,16 @@

- + + - - - - + + + + @@ -134,7 +137,7 @@
- + diff --git a/src/components/projects/SingleProject/SingleProject.ts b/src/components/projects/SingleProject/SingleProject.ts index 5adc9e4..b39585c 100644 --- a/src/components/projects/SingleProject/SingleProject.ts +++ b/src/components/projects/SingleProject/SingleProject.ts @@ -293,7 +293,7 @@ export default class SingleProject extends Vue { } get isMyProject() { - return this.itemproject.userId === UserStore.state.userId + return this.itemproject.userId === UserStore.state.my._id } get tipoProj() { diff --git a/src/globalroutines/indexdb.ts b/src/globalroutines/indexdb.ts index 1fa1fca..2d36551 100644 --- a/src/globalroutines/indexdb.ts +++ b/src/globalroutines/indexdb.ts @@ -15,7 +15,7 @@ function saveConfigIndexDb(context) { _id: costanti.CONFIG_ID_CFG, lang: toolsext.getLocale(), token: UserStore.state.x_auth_token, - userId: UserStore.state.userId + userId: UserStore.state.my._id } writeConfigIndexDb('config', data) diff --git a/src/layouts/toolbar/messagePopover/messagePopover.ts b/src/layouts/toolbar/messagePopover/messagePopover.ts index 05d3d3d..f2b0189 100644 --- a/src/layouts/toolbar/messagePopover/messagePopover.ts +++ b/src/layouts/toolbar/messagePopover/messagePopover.ts @@ -9,10 +9,14 @@ import { tools } from '@src/store/Modules/tools' import { toolsext } from '@src/store/Modules/toolsext' import { ITodo, ITodosState } from '../../../model' import { Getter } from 'vuex-class' +import { UserStore } from '../../../store/Modules' + +import MixinUsers from '../../../mixins/mixin-users' const namespace = 'UserModule' @Component({ + mixins: [MixinUsers] }) export default class MessagePopover extends Vue { @@ -25,6 +29,20 @@ export default class MessagePopover extends Vue { // } } + get getNumMsg() { + return UserStore.getters.getlasts_messages().length + } + + get getNumMsgUnread() { + // return UserStore.getters.getlasts_messages().length + return UserStore.getters.getnumMsgUnread() + } + + get getNumNotifUnread() { + // return UserStore.getters.getlasts_messages().length + return 0 + } + public randomDate(): Date { let myval = Math.floor(Math.random() * 10000000000) return tools.getstrDateTime(new Date(tools.getTimestampsNow() - myval)) diff --git a/src/layouts/toolbar/messagePopover/messagePopover.vue b/src/layouts/toolbar/messagePopover/messagePopover.vue index 6574ced..0f67b51 100644 --- a/src/layouts/toolbar/messagePopover/messagePopover.vue +++ b/src/layouts/toolbar/messagePopover/messagePopover.vue @@ -1,45 +1,49 @@ + + diff --git a/src/components/CMyEditor/index.ts b/src/components/CMyEditor/index.ts new file mode 100644 index 0000000..0d1666a --- /dev/null +++ b/src/components/CMyEditor/index.ts @@ -0,0 +1 @@ +export {default as CMyEditor} from './CMyEditor.vue' diff --git a/src/components/CMySelect/CMySelect.scss b/src/components/CMySelect/CMySelect.scss new file mode 100644 index 0000000..b892863 --- /dev/null +++ b/src/components/CMySelect/CMySelect.scss @@ -0,0 +1,4 @@ +.myflex{ + display: flex; + flex: 1; +} diff --git a/src/components/CMySelect/CMySelect.ts b/src/components/CMySelect/CMySelect.ts new file mode 100644 index 0000000..1edd9ae --- /dev/null +++ b/src/components/CMySelect/CMySelect.ts @@ -0,0 +1,56 @@ +import Vue from 'vue' +import { Component, Prop, Watch } from 'vue-property-decorator' + +import { tools } from '../../store/Modules/tools' +import { toolsext } from '@src/store/Modules/toolsext' +import { IPerson } from '../../model/GlobalStore' + +@Component({ + name: 'CMySelect' +}) + +export default class CMySelect extends Vue { + @Prop({ required: true }) public value + @Prop({ required: true, default: '' }) public label + @Prop({ required: false, default: '' }) public myclass + @Prop({ required: true, default: '' }) public optlab + @Prop({ required: true, default: '' }) public optval + @Prop({ required: false, default: true }) public useinput: boolean + @Prop({ required: false, default: null }) public newvaluefunc + @Prop({ required: false, default: null }) public funcgetvaluebyid + @Prop({ required: true }) public options + + public myvalue = '' + + get tools() { + return tools + } + + public nothing() { + + } + + public changeval(newval) { + console.log('changeval', newval) + // const newvallab = newval[`${this.optval}`] + // this.myvalue = newvallab + this.$emit('update:value', newval) + } + + public mounted() { + const rec = this.options.find((myrec) => myrec[`${this.optval}`] === this.value) + console.log('rec', rec) + if (!this.useinput) { + this.myvalue = this.value + } else { + if (rec) { + if (this.funcgetvaluebyid) + this.myvalue = this.funcgetvaluebyid(rec[`${this.optval}`]) + else + this.myvalue = rec[`${this.optlab}`] + + console.log('this.myvalue', this.myvalue, 'this.optval', this.optval, 'rec', rec[`${this.optval}`]) + } + } + } +} diff --git a/src/components/CMySelect/CMySelect.vue b/src/components/CMySelect/CMySelect.vue new file mode 100644 index 0000000..1014b7a --- /dev/null +++ b/src/components/CMySelect/CMySelect.vue @@ -0,0 +1,46 @@ + + + + + diff --git a/src/components/CMySelect/index.ts b/src/components/CMySelect/index.ts new file mode 100644 index 0000000..b894540 --- /dev/null +++ b/src/components/CMySelect/index.ts @@ -0,0 +1 @@ +export {default as CMySelect} from './CMySelect.vue' diff --git a/src/components/Header/Header.ts b/src/components/Header/Header.ts index 1d53a92..6921277 100644 --- a/src/components/Header/Header.ts +++ b/src/components/Header/Header.ts @@ -43,10 +43,6 @@ export default class Header extends Vue { public photo = '' public visuimg: boolean = true - get tools() { - return tools - } - get conn_changed() { return GlobalStore.state.stateConnection } diff --git a/src/components/Header/Header.vue b/src/components/Header/Header.vue index 17b67e5..d7012cd 100644 --- a/src/components/Header/Header.vue +++ b/src/components/Header/Header.vue @@ -108,7 +108,7 @@ - + @@ -137,7 +137,7 @@
- + diff --git a/src/components/Shen/CTesseraElettronica/CTesseraElettronica.scss b/src/components/Shen/CTesseraElettronica/CTesseraElettronica.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/components/Shen/CTesseraElettronica/CTesseraElettronica.ts b/src/components/Shen/CTesseraElettronica/CTesseraElettronica.ts new file mode 100644 index 0000000..82a0a06 --- /dev/null +++ b/src/components/Shen/CTesseraElettronica/CTesseraElettronica.ts @@ -0,0 +1,32 @@ +import Vue from 'vue' +import { Component, Prop } from 'vue-property-decorator' +import { SingleProject } from '../../projects/SingleProject' +import { CTodo } from '../../todos/CTodo' +import { GlobalStore } from '../../../store/Modules' + +@Component({}) +export default class CTesseraElettronica extends Vue { + public $q + public $t + public $refs: { + frametessera + } + + public mounted() { + // ... + // $('#frametessera').contents().find('#nome').val("PPPP") + } + + get getNome() { + return '' + } + get getFrame() { + + // console.log('getFrame', $('#frametessera')) + return '' + } + + get rightDrawerOpen() { + return GlobalStore.state.RightDrawerOpen + } +} diff --git a/src/components/Shen/CTesseraElettronica/CTesseraElettronica.vue b/src/components/Shen/CTesseraElettronica/CTesseraElettronica.vue new file mode 100644 index 0000000..19bcd98 --- /dev/null +++ b/src/components/Shen/CTesseraElettronica/CTesseraElettronica.vue @@ -0,0 +1,22 @@ + + + + diff --git a/src/components/Shen/CTesseraElettronica/index.ts b/src/components/Shen/CTesseraElettronica/index.ts new file mode 100644 index 0000000..ccfb91b --- /dev/null +++ b/src/components/Shen/CTesseraElettronica/index.ts @@ -0,0 +1 @@ +export {default as CTesseraElettronica} from './CTesseraElettronica.vue' diff --git a/src/layouts/toolbar/messagePopover/messagePopover.ts b/src/layouts/toolbar/messagePopover/messagePopover.ts index f2b0189..7a103ef 100644 --- a/src/layouts/toolbar/messagePopover/messagePopover.ts +++ b/src/layouts/toolbar/messagePopover/messagePopover.ts @@ -13,7 +13,7 @@ import { UserStore } from '../../../store/Modules' import MixinUsers from '../../../mixins/mixin-users' -const namespace = 'UserModule' +const namespace = 'MessageModule' @Component({ mixins: [MixinUsers] @@ -29,22 +29,17 @@ export default class MessagePopover extends Vue { // } } - get getNumMsg() { - return UserStore.getters.getlasts_messages().length - } - - get getNumMsgUnread() { - // return UserStore.getters.getlasts_messages().length - return UserStore.getters.getnumMsgUnread() + public clickChat(msg: IMessage){ + this.$router.replace('/messages/' + msg.dest.username) } get getNumNotifUnread() { - // return UserStore.getters.getlasts_messages().length + return 0 } public randomDate(): Date { - let myval = Math.floor(Math.random() * 10000000000) + const myval = Math.floor(Math.random() * 10000000000) return tools.getstrDateTime(new Date(tools.getTimestampsNow() - myval)) } @@ -79,10 +74,6 @@ export default class MessagePopover extends Vue { */ } - get tools() { - return tools - } - // public requestPosts() { // // console.log('requestPosts...') // let prova = [{ title: 'primo' }, { title: 'Secondo' }] diff --git a/src/layouts/toolbar/messagePopover/messagePopover.vue b/src/layouts/toolbar/messagePopover/messagePopover.vue index 0f67b51..04a9d45 100644 --- a/src/layouts/toolbar/messagePopover/messagePopover.vue +++ b/src/layouts/toolbar/messagePopover/messagePopover.vue @@ -15,11 +15,10 @@
- + - {{msg.origin.username}} diff --git a/src/mixins/mixin-users.ts b/src/mixins/mixin-users.ts index a3918c2..04d2921 100644 --- a/src/mixins/mixin-users.ts +++ b/src/mixins/mixin-users.ts @@ -1,11 +1,23 @@ import Vue from 'vue' -import { GlobalStore, UserStore } from '../store/Modules' +import { GlobalStore, UserStore, MessageStore } from '../store/Modules' + import Component from 'vue-class-component' +import { func_tools } from '../store/Modules/toolsext' +import { tools } from '../store/Modules/tools' // You can declare a mixin as the same style as components. @Component export default class MixinUsers extends Vue { + public mythis() { + return this + } + get func_tools() { + return func_tools + } + get tools() { + return tools + } public getUserByUsername(username) { return UserStore.getters.getNameSurnameByUsername(username) } @@ -16,7 +28,7 @@ export default class MixinUsers extends Vue { return UserStore.state.my.username } get getMyImg() { - return UserStore.getters.getImgByUsername(UserStore.state.my.username) + return 'statics/' + UserStore.getters.getImgByUsername(UserStore.state.my.username) } get MenuCollapse() { return GlobalStore.state.menuCollapse @@ -37,4 +49,13 @@ export default class MixinUsers extends Vue { get Email() { return UserStore.state.my.email } + get getNumMsg() { + return MessageStore.getters.getlasts_messages().length + } + + get getNumMsgUnread() { + // return UserStore.getters.getlasts_messages().length + return MessageStore.getters.getnumMsgUnread() + } + } diff --git a/src/model/Calendar.ts b/src/model/Calendar.ts index f923aeb..872f42f 100644 --- a/src/model/Calendar.ts +++ b/src/model/Calendar.ts @@ -41,29 +41,6 @@ export interface IBookedEvent { booked: boolean } -export interface IOrigin { - userId?: string - page?: string - event_id?: string - infoevent?: string -} - -export interface IDest { - idapp?: string - username?: string -} - -export interface IMessage { - _id?: any - idapp?: string - origin?: IOrigin - dest?: IDest - message: string - datemsg?: Date - read?: boolean - deleted?: boolean -} - export interface IOperators { username: string name: string @@ -101,11 +78,6 @@ export interface IBookedEventPage { state: EState } -export interface IMessagePage { - show: boolean - msg: IMessage - state: EState -} export interface ICalendarState { editable: boolean diff --git a/src/model/UserStore.ts b/src/model/UserStore.ts index 62c78d1..6715d6e 100644 --- a/src/model/UserStore.ts +++ b/src/model/UserStore.ts @@ -1,12 +1,11 @@ import { IToken } from 'model/other' -import { IMessage } from '@src/model/Calendar' export const DefaultUser: IUserFields = { email: '', username: '', name: '', surname: '', - password: '', + password: '' } export interface IUserFields { @@ -45,5 +44,4 @@ export interface IUserState { isManager?: boolean usersList?: IUserFields[] countusers?: number - msgs?: IMessage[] } diff --git a/src/model/index.ts b/src/model/index.ts index dcb8eb8..8e5e281 100644 --- a/src/model/index.ts +++ b/src/model/index.ts @@ -1,4 +1,5 @@ export * from './UserStore' +export * from './MessageStore' export * from './GlobalStore' export * from './signin-option' export * from './signup-option' diff --git a/src/statics/i18n.js b/src/statics/i18n.js index 18369d1..e0d16c7 100644 --- a/src/statics/i18n.js +++ b/src/statics/i18n.js @@ -18,6 +18,9 @@ const msgglobal = { }, manage: { menu: 'Gestione' + }, + messages: { + menu: 'I tuoi Messaggi' } }, sendmsg: { @@ -300,6 +303,9 @@ const msgglobal = { }, manage: { menu: 'Gestionar' + }, + messages: { + menu: 'Tus mensajes' } }, sendmsg: { @@ -573,6 +579,9 @@ const msgglobal = { }, manage: { menu: 'Gérer' + }, + messages: { + menu: 'Vos messages' } }, sendmsg: { @@ -845,6 +854,9 @@ const msgglobal = { }, manage: { menu: 'Manage' + }, + messages: { + menu: 'Your Messages' } }, sendmsg: { @@ -1116,6 +1128,9 @@ const msgglobal = { }, manage: { menu: 'Manage' + }, + messages: { + menu: 'Your Messages' } }, sendmsg: { diff --git a/src/store/Modules/GlobalStore.ts b/src/store/Modules/GlobalStore.ts index b2b545b..4bb0d22 100644 --- a/src/store/Modules/GlobalStore.ts +++ b/src/store/Modules/GlobalStore.ts @@ -13,7 +13,7 @@ import { costanti } from '@src/store/Modules/costanti' import { tools } from '@src/store/Modules/tools' import { toolsext } from '@src/store/Modules/toolsext' import * as ApiTables from '@src/store/Modules/ApiTables' -import { CalendarStore, GlobalStore, Projects, Todos, UserStore } from '@store' +import { CalendarStore, GlobalStore, MessageStore, Projects, Todos, UserStore } from '@store' import messages from '../../statics/i18n' import globalroutines from './../../globalroutines/index' @@ -283,7 +283,7 @@ namespace Mutations { else if (table === 'users') return UserStore.state.usersList else if (table === 'sendmsgs') - return UserStore.state.msgs + return MessageStore.state.last_msgs else return null @@ -535,11 +535,11 @@ namespace Actions { UserStore.mutations.setusersList(res.data.usersList) } - if (res.data.msgs) { - UserStore.state.msgs = [...res.data.msgs] + if (res.data.last_msgs) { + MessageStore.state.last_msgs = [...res.data.last_msgs] } - console.log('UserStore.state.msgs', UserStore.state.msgs) + // console.log('MessageStore.state.last_msgs', MessageStore.state.last_msgs) // console.log('********** res', 'state.todos', state.todos, 'checkPending', checkPending) // After Login will store into the indexedDb... diff --git a/src/store/Modules/UserStore.ts b/src/store/Modules/UserStore.ts index 86eb2b9..49cf5a8 100644 --- a/src/store/Modules/UserStore.ts +++ b/src/store/Modules/UserStore.ts @@ -17,7 +17,6 @@ import translate from './../../globalroutines/util' import * as Types from '@src/store/Api/ApiTypes' import { ICalendarState, ICfgServer } from '@src/model' import { shared_consts } from '../../common/shared_vuejs' -import { IMessage } from '@src/model/Calendar' const bcrypt = require('bcryptjs') @@ -42,7 +41,6 @@ const state: IUserState = { isAdmin: false, isManager: false, usersList: [], - msgs: [], countusers: 0 } @@ -142,7 +140,6 @@ namespace Getters { const getImgByUsername = b.read((mystate: IUserState) => (username): string => { // Check if is this User! const myrec = UserStore.getters.getUserByUsername(username) - console.log('getImgByUsername', username, myrec) if (myrec && !!myrec.img) { return myrec.img } else { @@ -150,17 +147,6 @@ namespace Getters { } }, 'getImgByUsername') - const getlasts_messages = b.read((mystate: IUserState) => () => { - const ctrec = (mystate.msgs) ? mystate.msgs.slice(0, 5) : [] - // const ctrec = (mystate.msgs) ? mystate.msgs.slice().reverse().slice(0, 5) : [] - return (ctrec) - - }, 'getlasts_messages') - - const getnumMsgUnread = b.read((mystate: IUserState) => () => { - return mystate.msgs.filter((msg) => !msg.read).length - }, 'getnumMsgUnread') - export const getters = { get isUserInvalid() { return isUserInvalid() @@ -200,14 +186,7 @@ namespace Getters { }, get getUsersList() { return getUsersList() - }, - get getlasts_messages() { - return getlasts_messages() - }, - get getnumMsgUnread() { - return getnumMsgUnread() } - // get fullName() { return fullName();}, } } @@ -720,28 +699,6 @@ namespace Actions { } } - async function SendMsgEvent(context, msg: IMessage) { - console.log('SendMsgEvent', msg) - - return await Api.SendReq('/sendmsg', 'POST', msg) - .then((res) => { - console.log('res', res) - if (res.status === 200) { - if (res.data.code === serv_constants.RIS_CODE_OK) { - msg._id = res.data.id - state.msgs.push(msg) - return true - } - } - return false - }) - .catch((error) => { - console.error(error) - return false - }) - - } - /* async function refreshUserInfos(){ let {token, refresh_token} = JWT.fetch(); @@ -765,7 +722,6 @@ namespace Actions { resetpwd: b.dispatch(resetpwd), signin: b.dispatch(signin), signup: b.dispatch(signup), - SendMsgEvent: b.dispatch(SendMsgEvent), vreg: b.dispatch(vreg) } diff --git a/src/store/Modules/index.ts b/src/store/Modules/index.ts index 941c962..22395c1 100644 --- a/src/store/Modules/index.ts +++ b/src/store/Modules/index.ts @@ -1,6 +1,7 @@ export {storeBuilder} from './Store/Store' export {default as GlobalStore} from './GlobalStore' export {default as UserStore} from './UserStore' +export {default as MessageStore} from './MessageStore' export {default as Todos} from './Todos' export {default as Projects} from './Projects' export {default as CalendarStore} from './Store/calendar/CalendarStore' diff --git a/src/store/Modules/serv_constants.ts b/src/store/Modules/serv_constants.ts index d220271..1823665 100644 --- a/src/store/Modules/serv_constants.ts +++ b/src/store/Modules/serv_constants.ts @@ -1,5 +1,6 @@ export const serv_constants = { RIS_CODE_TODO_CREATING_NOTMYUSER: -1001, + RIS_CODE_NOT_MY_USERNAME: -1010, RIS_CODE_ERR: -99, RIS_CODE_EMAIL_ALREADY_VERIFIED: -5, diff --git a/src/store/Modules/tools.ts b/src/store/Modules/tools.ts index 357c99a..0e03529 100644 --- a/src/store/Modules/tools.ts +++ b/src/store/Modules/tools.ts @@ -26,6 +26,9 @@ import { func_tools } from '@src/store/Modules/toolsext' import { serv_constants } from '@src/store/Modules/serv_constants' import { shared_consts } from '@src/common/shared_vuejs' +import { dom } from 'quasar' +const { height, width } = dom + export interface INotify { color?: string | 'primary' textColor?: string @@ -1737,8 +1740,11 @@ export const tools = { , getstrYYMMDDDateTime(mytimestamp) { return date.formatDate(mytimestamp, 'YYYY-MM-DD HH:mm') - } - , + }, + + getstrYYMMDDDateTimeAll(mytimestamp) { + return date.formatDate(mytimestamp, 'YYYY-MM-DD HH:mm:ss') + }, // mystrdate "26.04.2013" convertstrtoDate(mystrdate @@ -1801,8 +1807,11 @@ export const tools = { , getTimestampsNow() { return new Date().valueOf() - } - , + }, + + gettimestampByDate(mydate) { + return mydate.toString() + }, isMainProject(idproj) { return idproj === process.env.PROJECT_ID_MAIN @@ -2456,8 +2465,14 @@ export const tools = { } return record }) - } - , + }, + getheight(mythis) { + // return height() + return mythis.$q.screen.height + }, + getLastDateReadReset() { + return new Date(1999, 1, 1, 0, 0, 0) + }, isBitActive(bit, whattofind) { return ((bit & whattofind) === whattofind) diff --git a/src/views/messages/index.ts b/src/views/messages/index.ts new file mode 100644 index 0000000..7195f5d --- /dev/null +++ b/src/views/messages/index.ts @@ -0,0 +1 @@ +export {default as Messages} from './messages' diff --git a/src/views/messages/messages.scss b/src/views/messages/messages.scss new file mode 100644 index 0000000..5fca5c7 --- /dev/null +++ b/src/views/messages/messages.scss @@ -0,0 +1,33 @@ +.messages_page{ + margin-left: auto; + margin-right: auto; + margin-top: auto; + margin-bottom: auto; + min-height: 400px; +} + +.title_msg{ + font-weight: bold; +} + +.user{ + font-weight: bold; +} + +.active-user{ + color:blue; + background-color: rgba(174, 189, 241, 0.71); + border-radius: 1rem !important; +} + +.chat-list{ + border-radius: 20px; +} + +.chat_dest{ + +} + +.chat_my{ + +} diff --git a/src/views/messages/messages.ts b/src/views/messages/messages.ts new file mode 100644 index 0000000..61f7d86 --- /dev/null +++ b/src/views/messages/messages.ts @@ -0,0 +1,103 @@ +import Vue from 'vue' +import { Component, Prop, Watch } from 'vue-property-decorator' +import { toolsext } from '../../store/Modules/toolsext' +import { MessageStore, UserStore } from '../../store/Modules' +import globalroutines from '../../globalroutines/index' +import { tools } from '../../store/Modules/tools' +import MixinUsers from '../../mixins/mixin-users' +import { IChat, IMessage, IUserState } from '../../model' +import { Getter } from 'vuex-class' +import { IMsgUsers } from '../../model/MessageStore' + +// import {Loading, QSpinnerFacebook, QSpinnerGears} from 'quasar' + +const namespace = 'MessageModule' + +@Component({ + name: 'Messages', + mixins: [MixinUsers], + components: { } +}) + +export default class Messages extends Vue { + public $t + public $q + public mydrawer = true + public miniState = false + public chatsel: IChat = { + username: '', + lasttimeActive: new Date() + } + + @Getter('getlasts_messages', { namespace }) + public lasts_messages: (state: IUserState) => IMessage[] + + public showNotif(msgcode) { + tools.showNotif(this.$q, this.$t(msgcode)) + } + + public drawerClick(e) { + // if in "mini" state and user + // click on drawer, we switch it to "normal" mode + if (this.miniState) { + this.miniState = false + + // notice we have registered an event with capture flag; + // we need to stop further propagation as this click is + // intended for switching drawer to "normal" mode only + e.stopPropagation() + } + } + + get getheight() { + // return height() + return this.$q.screen.height - 43 // .toolbar + } + + public isMenuActive(username) { + return this.chatsel.username === username + } + + @Watch('$route.params.un') + public changeusername() { + this.chatsel.username = this.$route.params.un + if (!this.miniState && tools.isMobile()) { + this.miniState = true + } + + // Retrieve last msgs data from the server + MessageStore.actions.updateMsgDataFromServer({username: this.chatsel.username, lastdataread: this.getlastdataread() } ) + } + + public selChat(mymsg: IMessage) { + this.$router.replace('/messages/' + mymsg.dest.username) + } + + public msgchat(): IMsgUsers { + // Get msg for this chat + return MessageStore.state.users_msg.find((rec) => rec.username === this.chatsel.username) + } + + public msgchat_records(): IMessage[] { + const myrec = this.msgchat() + console.log('myrec', myrec) + // Get msg for this chat + return (myrec) ? myrec.msgs : [] + } + + public getlastdataread(): Date { + const myrec = this.msgchat() + // Get msg for this chat + return (myrec) ? tools.gettimestampByDate(myrec.lastdataread) : tools.getLastDateReadReset() + } + + public getMsgText(msg: IMessage) { + return [msg.message] + } + + public created() { + + this.changeusername() + } + +} diff --git a/src/views/messages/messages.vue b/src/views/messages/messages.vue new file mode 100644 index 0000000..2082d30 --- /dev/null +++ b/src/views/messages/messages.vue @@ -0,0 +1,136 @@ + + + + +