- ++Booking List

- ++Delete a Booking also for the Admin.
This commit is contained in:
Paolo Arena
2019-10-12 23:34:58 +02:00
parent bba0c05a73
commit eed1082ac6
23 changed files with 320 additions and 423 deletions

View File

@@ -10,6 +10,7 @@ import translate from '../../../../globalroutines/util'
import * as Types from '../../../Api/ApiTypes'
import { db_data } from '@src/db/db_data'
import { UserStore } from '@store'
import { lists } from '@src/store/Modules/lists'
// State
const state: ICalendarState = {
@@ -49,9 +50,27 @@ namespace Getters {
return mystate.bookedevent.find((bookedevent) => (bookedevent.id_bookedevent === myevent._id) && ((isconfirmed && bookedevent.booked) || (!isconfirmed)))
}, 'findEventBooked')
const getNumParticipants = b.read((mystate: ICalendarState) => (myevent: IEvents) => {
const myarr = mystate.bookedevent.filter((bookedevent) => (bookedevent.id_bookedevent === myevent._id) && (bookedevent.booked))
if (myarr)
return myarr.reduce((sum, bookedevent) => sum + bookedevent.numpeople, 0)
else
return 0
}, 'getNumParticipants')
const getEventsBookedByIdEvent = b.read((mystate: ICalendarState) => (idevent) => {
return mystate.bookedevent.filter((bookedevent) => (bookedevent.id_bookedevent === idevent) && (bookedevent.booked))
}, 'getEventsBookedByIdEvent')
export const getters = {
get findEventBooked() {
return findEventBooked()
},
get getNumParticipants() {
return getNumParticipants()
},
get getEventsBookedByIdEvent() {
return getEventsBookedByIdEvent()
}
}
@@ -86,7 +105,9 @@ namespace Actions {
let ris = null
ris = await Api.SendReq('/booking/' + UserStore.state.userId + '/' + process.env.APP_ID, 'GET', null)
const showall = UserStore.state.isAdmin ? '1' : '0'
ris = await Api.SendReq('/booking/' + UserStore.state.userId + '/' + process.env.APP_ID + '/' + showall, 'GET', null)
.then((res) => {
if (res.data.bookedevent) {
state.bookedevent = res.data.bookedevent
@@ -106,6 +127,7 @@ namespace Actions {
function getparambyevent(bookevent) {
return {
_id: bookevent._id,
id_bookedevent: bookevent.id_bookedevent,
infoevent: bookevent.infoevent,
numpeople: bookevent.numpeople,
@@ -113,7 +135,7 @@ namespace Actions {
datebooked: bookevent.datebooked,
userId: UserStore.state.userId,
booked: bookevent.booked,
modified: bookevent.modified,
modified: bookevent.modified
}
}
@@ -126,6 +148,7 @@ namespace Actions {
.then((res) => {
if (res.status === 200) {
if (res.data.code === serv_constants.RIS_CODE_OK) {
bookevent._id = res.data.id
if (bookevent.modified) {
const foundIndex = state.bookedevent.findIndex((x) => x.id_bookedevent === bookevent.id_bookedevent)
@@ -147,20 +170,16 @@ namespace Actions {
}
async function CancelBookingEvent(context, event: IEvents) {
console.log('CALSTORE: CancelBookingEvent', event)
async function CancelBookingEvent(context, { ideventbook, notify }) {
console.log('CALSTORE: CancelBookingEvent', ideventbook, notify)
const myeventtoCancel = state.bookedevent.find((eventbooked) => (eventbooked.id_bookedevent === event._id))
const param = getparambyevent(myeventtoCancel)
param.booked = false // Cancel Booking
return await Api.SendReq('/booking', 'POST', param)
return await Api.SendReq('/booking/' + ideventbook + '/' + notify + '/' + process.env.APP_ID, 'DELETE', null)
.then((res) => {
if (res.status === 200) {
if (res.data.code === serv_constants.RIS_CODE_OK) {
state.bookedevent = state.bookedevent.filter((eventbooked) => (eventbooked.id_bookedevent !== event._id))
// Remove this record from my list
state.bookedevent = state.bookedevent.filter((eventbooked) => (eventbooked._id !== ideventbook))
return true
}
@@ -173,8 +192,6 @@ namespace Actions {
// UserStore.mutations.setErrorCatch(error)
return false
})
}
export const actions = {

View File

@@ -1,5 +1,5 @@
import Api from '@api'
import { ISignupOptions, ISigninOptions, IUserState } from 'model'
import { ISignupOptions, ISigninOptions, IUserState, IUserList } from 'model'
import { ILinkReg, IResult, IIdToken, IToken } from 'model/other'
import { storeBuilder } from './Store/Store'
import router from '@router'
@@ -11,6 +11,7 @@ import { GlobalStore, UserStore, Todos, Projects, BookingStore, CalendarStore }
import globalroutines from './../../globalroutines/index'
import { static_data } from '@src/db/static_data'
import { db_data } from '@src/db/db_data'
import translate from './../../globalroutines/util'
import * as Types from '@src/store/Api/ApiTypes'
@@ -33,7 +34,8 @@ const state: IUserState = {
servercode: 0,
x_auth_token: '',
isLogged: false,
isAdmin: false
isAdmin: false,
usersList: []
}
const b = storeBuilder.module<IUserState>('UserModule', state)
@@ -81,6 +83,14 @@ namespace Getters {
return state.servercode
}, 'getServerCode')
const getNameSurnameByUserId = b.read((state: IUserState) => (userId: string) => {
const user = UserStore.getters.getUserByUserId(userId)
if (user)
return user.name + ' ' + user.surname
else
return '(' + userId + ')'
}, 'getNameSurnameByUserId')
const IsMyFriend = b.read((state) => (userIdOwner) => {
// ++TODO Check if userIdOwner is my friend
// userIdOwner is my friend ?
@@ -93,6 +103,10 @@ namespace Getters {
return true
}, 'IsMyGroup')
const getUserByUserId = b.read((mystate: IUserState) => (userId): IUserState => {
return mystate.usersList.find((item) => item.userId === userId)
}, 'getUserByUserId')
export const getters = {
get isUserInvalid() {
return isUserInvalid()
@@ -114,6 +128,12 @@ namespace Getters {
},
get IsMyGroup() {
return IsMyGroup()
},
get getNameSurnameByUserId() {
return getNameSurnameByUserId()
},
get getUserByUserId() {
return getUserByUserId()
}
// get fullName() { return fullName();},
}
@@ -138,8 +158,10 @@ namespace Mutations {
state.tokens.push({ access: 'auth', token: state.x_auth_token, data_login: tools.getDateNow() })
// ++Todo: Settings Users Admin
if (state.username === 'paoloar77') {
if (db_data.adminUsers.includes(state.username)) {
state.isAdmin = true
} else {
state.isAdmin = false
}
// console.log('state.tokens', state.tokens)
@@ -389,7 +411,9 @@ namespace Actions {
localStorage.setItem(tools.localStorage.token, state.x_auth_token)
localStorage.setItem(tools.localStorage.expirationDate, expirationDate.toString())
localStorage.setItem(tools.localStorage.verified_email, String(false))
state.isLogged = true
// Even if you has registered, you have to SignIn first
state.isLogged = false
// dispatch('storeUser', authData);
// dispatch('setLogoutTimer', myres.data.expiresIn);

View File

@@ -3,8 +3,18 @@ import globalroutines from './../../globalroutines/index'
import { costanti } from './costanti'
import { toolsext } from './toolsext'
import { translation } from './translation'
import Quasar, { date, Screen } from 'quasar'
import { ICollaborations, IListRoutes, IMenuList, IParamDialog, IProject, ITodo, Privacy } from '@src/model'
import Quasar, { colors, date, Screen } from 'quasar'
import {
IBookedEvent,
ICollaborations,
IEvents,
IListRoutes,
IMenuList,
IParamDialog,
IProject,
ITodo,
Privacy
} from '@src/model'
import * as ApiTables from '@src/store/Modules/ApiTables'
import translate from '@src/globalroutines/util'
import { RouteNames } from '@src/router/route-names'
@@ -1302,13 +1312,14 @@ export const tools = {
return result
},
executefunc(myself: any, myfunc: number, par: IParamDialog) {
if (myfunc === costanti.FuncDialog.CANCEL_BOOKING) {
console.log(' ENTRATO ! CancelBookingEvent ')
CalendarStore.actions.CancelBookingEvent(par.param1).then((ris) => {
executefunc(myself: any, func: number, par: IParamDialog) {
if (func === lists.MenuAction.DELETE) {
console.log('param1', par.param1)
CalendarStore.actions.CancelBookingEvent({ideventbook: par.param1, notify: par.param2 === true ? '1' : '0'}).then((ris) => {
if (ris) {
tools.showPositiveNotif(myself.$q, myself.$t('cal.canceledbooking') + ' "' + par.param1.title + '"')
myself.bookEventpage.show = false
if (myself.bookEventpage)
myself.bookEventpage.show = false
} else
tools.showNegativeNotif(myself.$q, myself.$t('cal.cancelederrorbooking'))
})
@@ -2078,7 +2089,7 @@ export const tools = {
return msg
},
gettextevent(myevent) {
gettextevent(myevent: IEvents) {
return '"' + myevent.title + '" (' + func_tools.getDateStr(myevent.date) + ') - ' + myevent.time
},
@@ -2126,7 +2137,7 @@ export const tools = {
globalroutines(mythis, 'loadapp', '')
tools.checkErrors(mythis, tools.OK, ispageLogin)
tools.SignIncheckErrors(mythis, tools.OK, ispageLogin)
},
loginInCorso(mythis) {
@@ -2139,8 +2150,8 @@ export const tools = {
mythis.$q.loading.show({ message: msg })
},
checkErrors(mythis, riscode, ispageLogin?: boolean) {
// console.log('checkErrors: ', riscode)
SignIncheckErrors(mythis, riscode, ispageLogin?: boolean) {
// console.log('SignIncheckErrors: ', riscode)
try {
if (riscode === tools.OK) {
tools.showNotif(mythis.$q, mythis.$t('login.completato'), { color: 'positive', icon: 'check' })
@@ -2185,8 +2196,51 @@ export const tools = {
} finally {
// ...
}
}
},
SignUpcheckErrors(mythis, riscode: number) {
console.log('SignUpcheckErrors', riscode)
if (riscode === tools.DUPLICATE_EMAIL_ID) {
tools.showNotif(mythis.$q, mythis.$t('reg.err.duplicate_email'))
} else if (riscode === tools.DUPLICATE_USERNAME_ID) {
tools.showNotif(mythis.$q, mythis.$t('reg.err.duplicate_username'))
} else if (riscode === tools.ERR_SERVERFETCH) {
tools.showNotif(mythis.$q, mythis.$t('fetch.errore_server'))
} else if (riscode === tools.ERR_GENERICO) {
const msg = mythis.$t('fetch.errore_generico') + UserStore.mutations.getMsgError(riscode)
tools.showNotif(mythis.$q, msg)
} else if (riscode === tools.OK) {
mythis.$router.push('/signin')
tools.showNotif(mythis.$q, mythis.$t('components.authentication.email_verification.link_sent'), {
color: 'warning',
textColor: 'black'
})
} else {
tools.showNotif(mythis.$q, 'Errore num ' + riscode)
}
},
isCssColor(color) {
return !!color && !!color.match(/^(#|(rgb|hsl)a?\()/)
},
displayClasses(eventparam) {
return {
[`bg-${eventparam.bgcolor}`]: !tools.isCssColor(eventparam.bgcolor),
'text-white': !tools.isCssColor(eventparam.bgcolor)
}
},
displayStyles(eventparam) {
const s = { color: '' }
if (tools.isCssColor(eventparam.bgcolor)) {
s['background-color'] = eventparam.bgcolor
s.color = colors.luminosity(eventparam.bgcolor) > 0.5 ? 'black' : 'white'
}
return s
},
CancelBookingEvent(mythis, eventparam: IEvents, bookeventid: string, notify: boolean) {
console.log('CancelBookingEvent ', eventparam)
tools.askConfirm(mythis.$q, translate('cal.titlebooking'), translate('cal.cancelbooking') + ' ' + tools.gettextevent(eventparam) + '?', translate('dialog.yes'), translate('dialog.no'), mythis, lists.MenuAction.DELETE, 0, { param1: bookeventid, param2: notify })
}
// getLocale() {
// if (navigator.languages && navigator.languages.length > 0) {

View File

@@ -38,6 +38,21 @@ export const func_tools = {
return DateFormatter.format(date)
}
return mydate
},
getDateTimeShortStr(mydate) {
const DateFormatter = new Intl.DateTimeFormat(func_tools.getLocale() || void 0, {
hour: 'numeric',
minute: 'numeric',
day: 'numeric',
month: 'short'
// timeZone: 'UTC'
})
if (DateFormatter) {
const date = new Date(mydate)
return DateFormatter.format(date)
}
return mydate
}
}