continua upgrade Vue 3
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import axios, { AxiosInstance, AxiosResponse } from 'axios'
|
||||
// import LoginModule from '../Modules/Auth/LoginStore'
|
||||
import router from '@router'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
import { toolsext } from '@src/store/Modules/toolsext'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
@@ -122,7 +121,7 @@ async function Request(type: string, path: string, payload: any): Promise<Types.
|
||||
ricevuto = true
|
||||
return new Types.AxiosSuccess(response.data, response.status)
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
setTimeout(() => {
|
||||
globalStore.connData.uploading_server = (globalStore.connData.uploading_server === 1) ? -1 : globalStore.connData.uploading_server
|
||||
globalStore.connData.downloading_server = (globalStore.connData.downloading_server === 1) ? -1 : globalStore.connData.downloading_server
|
||||
|
||||
173
src/store/MessageStore.ts
Executable file
173
src/store/MessageStore.ts
Executable file
@@ -0,0 +1,173 @@
|
||||
import Api from '@api'
|
||||
import { storeBuilder } from './Store/Store'
|
||||
|
||||
import { serv_constants } from '../Modules/serv_constants'
|
||||
import { toolsext } from '@src/store/Modules/toolsext'
|
||||
import { GlobalStore, UserStore, Todos, Projects, CalendarStore } from '@store'
|
||||
|
||||
import { IMessage, IMessageState, StatusMessage } from '../../model'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
import { MsgDefault } from '@src/model'
|
||||
import { shared_consts } from '@src/common/shared_vuejs'
|
||||
|
||||
// State
|
||||
const state: IMessageState = {
|
||||
last_msgs: [],
|
||||
users_msg: []
|
||||
// last_update: []
|
||||
}
|
||||
|
||||
const b = storeBuilder.module<IMessageState>('MessageModule', state)
|
||||
|
||||
namespace Getters {
|
||||
|
||||
const getlasts_messages = b.read((mystate: IMessageState) => (): IMessage[] => {
|
||||
const ctrec = (mystate.last_msgs) ? mystate.last_msgs.slice(0, 5) : []
|
||||
// const ctrec = (mystate.msgs) ? mystate.msgs.slice().reverse().slice(0, 5) : []
|
||||
return (ctrec)
|
||||
|
||||
}, 'getlasts_messages')
|
||||
|
||||
const getnumMsgUnread = b.read((mystate: IMessageState) => () => {
|
||||
return mystate.last_msgs.filter((msg) => !msg.read).length
|
||||
}, 'getnumMsgUnread')
|
||||
|
||||
export const getters = {
|
||||
get getlasts_messages() {
|
||||
return getlasts_messages()
|
||||
},
|
||||
get getnumMsgUnread() {
|
||||
return getnumMsgUnread()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Mutations {
|
||||
export const mutations = {
|
||||
}
|
||||
}
|
||||
|
||||
function setMsg(arrmsg: IMessage[], username) {
|
||||
// console.log('arrmsg', arrmsg)
|
||||
if (arrmsg.length > 0) {
|
||||
let users_msg = state.users_msg.find((rec) => rec.username === username)
|
||||
if (!users_msg) {
|
||||
state.users_msg.push({ username, msgs: [] })
|
||||
users_msg = state.users_msg.find((rec) => rec.username === username)
|
||||
}
|
||||
users_msg.msgs.push(...arrmsg)
|
||||
// console.table(users_msg.msgs)
|
||||
|
||||
// users_msg.msgs = tools.getUnique(users_msg.msgs, '_id')
|
||||
// console.table(users_msg.msgs)
|
||||
|
||||
if (users_msg.msgs) {
|
||||
let userother = users_msg.msgs.slice(-1)[0].dest.username
|
||||
if (userother === UserStore.state.my.username)
|
||||
userother = users_msg.msgs.slice(-1)[0].origin.username
|
||||
|
||||
let index = state.last_msgs.findIndex((rec) => (rec.dest.username === userother) || (rec.origin.username === userother))
|
||||
if (index >= 0) {
|
||||
// Update last message
|
||||
state.last_msgs[index] = users_msg.msgs.slice(-1)[0]
|
||||
} else {
|
||||
state.last_msgs.push(users_msg.msgs.slice(-1)[0])
|
||||
index = state.last_msgs.findIndex((rec) => (rec.dest.username === userother) || (rec.origin.username === userother))
|
||||
}
|
||||
if (state.last_msgs[index])
|
||||
users_msg.lastdataread = state.last_msgs[index].datemsg
|
||||
else
|
||||
users_msg.lastdataread = tools.getLastDateReadReset()
|
||||
|
||||
} else {
|
||||
users_msg.lastdataread = tools.getLastDateReadReset()
|
||||
}
|
||||
|
||||
// console.log('RICeVUTO', arrmsg, 'lastdataread', users_msg.lastdataread)
|
||||
// console.log('state.users_msg', users_msg)
|
||||
}
|
||||
}
|
||||
|
||||
namespace Actions {
|
||||
|
||||
async function updateMsgDataFromServer(context, { username, lastdataread } ) {
|
||||
// console.log('updateMsgDataFromServer', username, lastdataread)
|
||||
|
||||
return await Api.SendReq(`/sendmsg/${username}/${lastdataread}/${process.env.APP_ID}`, 'GET', null)
|
||||
.then((res) => {
|
||||
// console.log('res', res)
|
||||
if (res.status === 200) {
|
||||
setMsg(res.data.arrmsg, username)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
return false
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async function SendMsgEvent(context, msg: IMessage) {
|
||||
console.log('SendMsgEvent', msg)
|
||||
|
||||
const data: IMessage = { ...MsgDefault, ...msg}
|
||||
|
||||
data.source.page = ''
|
||||
data.idapp = process.env.APP_ID
|
||||
data.origin.idapp = process.env.APP_ID
|
||||
data.origin.username = UserStore.state.my.username
|
||||
data.datemsg = tools.getDateNow()
|
||||
data.status = StatusMessage.WaitingToSend
|
||||
// Options
|
||||
data.options = tools.SetBit(data.options, shared_consts.MessageOptions.Notify_ByEmail)
|
||||
data.options = tools.SetBit(data.options, shared_consts.MessageOptions.Notify_ByPushNotification)
|
||||
|
||||
// console.log('DOPO:')
|
||||
// console.table(data)
|
||||
|
||||
return await Api.SendReq('/sendmsg', 'POST', data)
|
||||
.then((res) => {
|
||||
// console.log('res', res)
|
||||
if (res.status === 200) {
|
||||
if (res.data.code === serv_constants.RIS_CODE_OK) {
|
||||
data._id = res.data.id
|
||||
|
||||
const myarr = []
|
||||
myarr.push(data)
|
||||
|
||||
setMsg(myarr, data.dest.username)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
return false
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
updateMsgDataFromServer: b.dispatch(updateMsgDataFromServer),
|
||||
SendMsgEvent: b.dispatch(SendMsgEvent)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const stateGetter = b.state()
|
||||
|
||||
// Module
|
||||
const MessageModule = {
|
||||
get state() {
|
||||
return stateGetter()
|
||||
},
|
||||
actions: Actions.actions,
|
||||
getters: Getters.getters,
|
||||
mutations: Mutations.mutations
|
||||
}
|
||||
|
||||
export default MessageModule
|
||||
File diff suppressed because it is too large
Load Diff
382
src/store/Products.ts
Executable file
382
src/store/Products.ts
Executable file
@@ -0,0 +1,382 @@
|
||||
import { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState } from 'model'
|
||||
|
||||
import Api from '@api'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
import * as Types from '@src/store/Api/ApiTypes'
|
||||
import { static_data } from '@src/db/static_data'
|
||||
import { shared_consts } from '@src/common/shared_vuejs'
|
||||
import { tools } from "@store/Modules/tools"
|
||||
import { defineStore } from "pinia"
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { toolsext } from "@store/Modules/toolsext"
|
||||
|
||||
export const useProducts = defineStore('Products', {
|
||||
state: (): IProductsState => ({
|
||||
products: [],
|
||||
cart: { items: [], totalPrice: 0, totalQty: 0, userId: '' },
|
||||
orders: []
|
||||
}),
|
||||
|
||||
getters: {
|
||||
getProducts: (state: IProductsState) => (): IProduct[] => {
|
||||
return state.products
|
||||
},
|
||||
|
||||
getCart: (state: IProductsState) => (): ICart => {
|
||||
return state.cart
|
||||
},
|
||||
|
||||
getOrdersAllCart: (state: IProductsState) => (): IOrderCart[] => {
|
||||
return state.orders
|
||||
},
|
||||
|
||||
getOrdersCart: (state: IProductsState) => (tipoord: string): IOrderCart[] | undefined => {
|
||||
console.log('state.orders', state.orders)
|
||||
if (tipoord === 'incorso')
|
||||
return state.orders.filter((rec: IOrderCart) => (rec.status ? rec.status : 0) <= shared_consts.OrderStatus.CHECKOUT_SENT)
|
||||
else if (tipoord === 'confermati')
|
||||
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.ORDER_CONFIRMED)
|
||||
else if (tipoord === 'pagati')
|
||||
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.PAYED)
|
||||
else if (tipoord === 'completati')
|
||||
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.RECEIVED)
|
||||
else if (tipoord === 'cancellati')
|
||||
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.CANCELED)
|
||||
},
|
||||
|
||||
existProductInCart: (state: IProductsState) => (idproduct: string): boolean => {
|
||||
// console.log('.cart.items', this.cart.items)
|
||||
if (state.cart.items) {
|
||||
const ris = state.cart.items.filter((item: IBaseOrder) => item.order.idProduct === idproduct).reduce((sum, rec) => sum + 1, 0)
|
||||
return ris > 0
|
||||
}
|
||||
return false
|
||||
},
|
||||
|
||||
getRecordEmpty: (state: IProductsState) => (): IProduct => {
|
||||
|
||||
const tomorrow = tools.getDateNow()
|
||||
tomorrow.setDate(tomorrow.getDate() + 1)
|
||||
|
||||
return {
|
||||
// _id: tools.getDateNow().toISOString(), // Create NEW
|
||||
active: false,
|
||||
idProducer: '',
|
||||
idStorehouses: [],
|
||||
producer: {},
|
||||
storehouses: [],
|
||||
code: '',
|
||||
name: '',
|
||||
description: '',
|
||||
department: '',
|
||||
category: '',
|
||||
price: 0.0,
|
||||
color: '',
|
||||
size: '',
|
||||
quantityAvailable: 0,
|
||||
canBeShipped: false,
|
||||
canBeBuyOnline: false,
|
||||
weight: 0,
|
||||
stars: 0,
|
||||
date: tools.getDateNow(),
|
||||
icon: '',
|
||||
img: ''
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
actions: {
|
||||
getProductsByCategory(category: string): any[] {
|
||||
return this.products.filter((rec) => rec.category === category)
|
||||
},
|
||||
|
||||
createOrderByProduct(product: IProduct, order: IOrder): IOrder {
|
||||
const userStore = useUserStore()
|
||||
const myorder: IOrder = {
|
||||
userId: userStore.my._id,
|
||||
idapp: process.env.APP_ID,
|
||||
idProduct: product._id,
|
||||
idProducer: product.idProducer,
|
||||
status: shared_consts.OrderStatus.IN_CART,
|
||||
price: product.price,
|
||||
after_price: product.after_price,
|
||||
color: product.color,
|
||||
size: product.size,
|
||||
weight: product.weight,
|
||||
|
||||
quantity: order.quantity,
|
||||
idStorehouse: order.idStorehouse
|
||||
}
|
||||
|
||||
if (product.storehouses.length === 1) {
|
||||
order.idStorehouse = product.storehouses[0]._id
|
||||
}
|
||||
|
||||
return myorder
|
||||
},
|
||||
|
||||
initcat() {
|
||||
|
||||
// rec.userId = userStore.my._id
|
||||
|
||||
return this.getRecordEmpty()
|
||||
|
||||
},
|
||||
|
||||
async loadProducts() {
|
||||
|
||||
const userStore = useUserStore()
|
||||
console.log('loadProducts')
|
||||
|
||||
if (!static_data.functionality.ENABLE_ECOMMERCE)
|
||||
return null
|
||||
|
||||
console.log('getProducts', 'userid=', userStore.my._id)
|
||||
|
||||
// if (userStore.my._id === '') {
|
||||
// return new Types.AxiosError(0, null, 0, '')
|
||||
// }
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/products', 'POST', null)
|
||||
.then((res) => {
|
||||
if (res.data.products) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
this.products = res.data.products
|
||||
} else {
|
||||
this.products = []
|
||||
}
|
||||
|
||||
// console.log('ARRAY PRODUCTS = ', this.products)
|
||||
if (process.env.DEBUG === '1') {
|
||||
// console.log('dbLoad', 'this.products', this.products)
|
||||
}
|
||||
|
||||
return res
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error getProducts', error)
|
||||
userStore.setErrorCatch(error)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error)
|
||||
})
|
||||
|
||||
// ApiTables.aftercalling(ris, checkPending, 'categories')
|
||||
|
||||
return ris
|
||||
},
|
||||
|
||||
async loadProduct({ code }: {code: any}) {
|
||||
|
||||
console.log('loadProduct', code)
|
||||
const userStore = useUserStore()
|
||||
|
||||
if (!static_data.functionality.ENABLE_ECOMMERCE)
|
||||
return null
|
||||
|
||||
console.log('getProduct', 'code', code)
|
||||
|
||||
// if (userStore.my._id === '') {
|
||||
// return new Types.AxiosError(0, null, 0, '')
|
||||
// }
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/products/' + code, 'POST', { code })
|
||||
.then((res) => {
|
||||
console.log('product', res.data.product)
|
||||
if (res.data.product) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
return res.data.product
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error getProduct', error)
|
||||
userStore.setErrorCatch(error)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error)
|
||||
})
|
||||
|
||||
return ris
|
||||
},
|
||||
|
||||
async loadOrders() {
|
||||
|
||||
console.log('loadOrders')
|
||||
const userStore = useUserStore()
|
||||
|
||||
if (!static_data.functionality.ENABLE_ECOMMERCE)
|
||||
return null
|
||||
|
||||
console.log('loadOrders', 'userid=', userStore.my._id)
|
||||
|
||||
// if (userStore.my._id === '') {
|
||||
// return new Types.AxiosError(0, null, 0, '')
|
||||
// }
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id, 'GET', null)
|
||||
.then((res) => {
|
||||
if (res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
this.cart = res.data.cart
|
||||
} else {
|
||||
this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
|
||||
}
|
||||
|
||||
return res
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error loadOrders', error)
|
||||
userStore.setErrorCatch(error)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error)
|
||||
})
|
||||
|
||||
// ApiTables.aftercalling(ris, checkPending, 'categories')
|
||||
|
||||
return ris
|
||||
},
|
||||
|
||||
async removeFromCart({ order }: {order: IOrder}) {
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
return await Api.SendReq('/cart/' + userStore.my._id, 'DELETE', { orderId: order._id })
|
||||
.then((res) => {
|
||||
if (res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
this.cart = res.data.cart
|
||||
} else {
|
||||
this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
|
||||
}
|
||||
|
||||
return res
|
||||
})
|
||||
},
|
||||
|
||||
async addToCart({ product, order }: {product: IProduct, order: IOrder}) {
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
if (!static_data.functionality.ENABLE_ECOMMERCE)
|
||||
return null
|
||||
|
||||
const neworder = this.createOrderByProduct(product, order)
|
||||
|
||||
if (!neworder.idStorehouse)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, 'Nessuno Store')
|
||||
|
||||
console.log('addToCart', 'userid=', userStore.my._id, neworder)
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id, 'POST', { order: neworder })
|
||||
.then((res) => {
|
||||
if (res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
this.cart = res.data.cart
|
||||
} else {
|
||||
this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
|
||||
}
|
||||
|
||||
return res
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error addToCart', error)
|
||||
userStore.setErrorCatch(error)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error)
|
||||
})
|
||||
|
||||
// ApiTables.aftercalling(ris, checkPending, 'categories')
|
||||
|
||||
return ris
|
||||
},
|
||||
|
||||
async addSubQtyToItem({ addqty, subqty, order } : { addqty: number, subqty: number, order: IOrder}) {
|
||||
|
||||
const userStore = useUserStore()
|
||||
if (!static_data.functionality.ENABLE_ECOMMERCE)
|
||||
return null
|
||||
|
||||
// console.log('addSubQtyToItem', 'userid=', userStore.my._id, order)
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id, 'POST', { addqty, subqty, order })
|
||||
.then((res) => {
|
||||
this.cart = res.data.cart
|
||||
if (!!res.data.qty) {
|
||||
// const ind = this.cart.items.findIndex((rec) => rec.order._id === order._id)
|
||||
// this.cart.items[ind].order.quantity = res.data.qty
|
||||
|
||||
return res.data.qty
|
||||
}
|
||||
|
||||
return 0
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error addSubQtyToItem', error)
|
||||
userStore.setErrorCatch(error)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error)
|
||||
})
|
||||
|
||||
// ApiTables.aftercalling(ris, checkPending, 'categories')
|
||||
|
||||
return ris
|
||||
},
|
||||
|
||||
async UpdateStatusCart({ cart_id, status }: { cart_id:string, status: number }) {
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
if (!static_data.functionality.ENABLE_ECOMMERCE)
|
||||
return null
|
||||
|
||||
// console.log('addSubQtyToItem', 'userid=', userStore.my._id, order)
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id + '/cartstatus', 'POST', { cart_id, status })
|
||||
.then((res) => {
|
||||
|
||||
if (res.data.status === shared_consts.OrderStatus.CHECKOUT_SENT) {
|
||||
this.cart = {}
|
||||
if (res.data.orders)
|
||||
this.orders = res.data.orders
|
||||
}
|
||||
return res.data.status
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error UpdateStatusCart', error)
|
||||
userStore.setErrorCatch(error)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error)
|
||||
})
|
||||
|
||||
return ris
|
||||
},
|
||||
|
||||
async UpdateOrderStatus({ order_id, status }: { order_id: string, status: number }) {
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
if (!static_data.functionality.ENABLE_ECOMMERCE)
|
||||
return null
|
||||
|
||||
// console.log('addSubQtyToItem', 'userid=', userStore.my._id, order)
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id + '/orderstatus', 'POST', { order_id, status })
|
||||
.then((res) => {
|
||||
return res.data.status
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error UpdateOrderStatus', error)
|
||||
userStore.setErrorCatch(error)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error)
|
||||
})
|
||||
|
||||
return ris
|
||||
},
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
558
src/store/Projects.ts
Executable file
558
src/store/Projects.ts
Executable file
@@ -0,0 +1,558 @@
|
||||
import { IProject, IProjectsState, IDrag, IMenuList, IAction } from 'model'
|
||||
import { Privacy, TipoVisu } from '@src/model'
|
||||
|
||||
import Api from '@api'
|
||||
import { tools } from './Modules/tools'
|
||||
import { toolsext } from '@src/store/Modules/toolsext'
|
||||
import { lists } from './Modules/lists'
|
||||
import * as ApiTables from './Modules/ApiTables'
|
||||
import globalroutines from './../globalroutines/index'
|
||||
import objectId from '@src/js/objectId'
|
||||
import { costanti } from '@src/store/Modules/costanti'
|
||||
import { RouteNames } from '@src/router/route-names'
|
||||
import * as Types from '@src/store/Api/ApiTypes'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
import { static_data } from '@src/db/static_data'
|
||||
import { defineStore } from "pinia"
|
||||
import { useUserStore } from "@store/UserStore"
|
||||
import { useGlobalStore } from "@store/globalStore"
|
||||
|
||||
const nametable = 'projects'
|
||||
|
||||
// import _ from 'lodash'
|
||||
|
||||
|
||||
const listFieldsToChange: string [] = ['descr', 'respUsername', 'viceRespUsername', 'vice2RespUsername', 'longdescr', 'hoursplanned', 'hoursleft', 'hoursworked', 'id_parent', 'statusproj',
|
||||
'category', 'expiring_at', 'priority', 'pos', 'groupId', 'enableExpiring', 'progressCalc', 'live_url', 'test_url',
|
||||
'begin_development', 'begin_test', 'actualphase', 'totalphases', 'hoursweeky_plannedtowork', 'endwork_estimate',
|
||||
'privacyread', 'privacywrite', 'tipovisu', 'id_main_project', 'typeproj', 'favourite', 'themecolor', 'themebgcolor', 'view']
|
||||
|
||||
const listFieldsUpdateCalculation: string [] = ['hoursplanned', 'hoursleft', 'hoursworked', 'progressCalc', 'endwork_estimate']
|
||||
|
||||
export const useProjectStore = defineStore('Projects', {
|
||||
state: (): IProjectsState => ({
|
||||
showtype: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED,
|
||||
projects: [],
|
||||
insidePending: false,
|
||||
visuLastCompleted: 10
|
||||
}),
|
||||
|
||||
getters: {
|
||||
|
||||
getRecordEmpty: (state: IProjectsState) => (): IProject => {
|
||||
// const tomorrow = tools.getDateNow()
|
||||
// tomorrow.setDate(tomorrow.getDate() + 1)
|
||||
|
||||
const obj: IProject = {
|
||||
_id: objectId(),
|
||||
descr: '',
|
||||
longdescr: '',
|
||||
typeproj: 0,
|
||||
id_parent: '',
|
||||
id_main_project: '',
|
||||
priority: tools.Priority.PRIORITY_NORMAL,
|
||||
statusproj: tools.Status.OPENED,
|
||||
created_at: tools.getDateNow(),
|
||||
modify_at: tools.getDateNow(),
|
||||
completed_at: tools.getDateNull(),
|
||||
category: '',
|
||||
// expiring_at: tomorrow,
|
||||
enableExpiring: false,
|
||||
pos: 0,
|
||||
modified: false,
|
||||
live_url: '',
|
||||
test_url: '',
|
||||
totalphases: 1,
|
||||
actualphase: 1,
|
||||
hoursworked: 0,
|
||||
hoursplanned: 0,
|
||||
hoursleft: 0,
|
||||
progressCalc: 0,
|
||||
privacyread: 'inherited',
|
||||
privacywrite: 'inherited',
|
||||
begin_development: tools.getDateNull(),
|
||||
begin_test: tools.getDateNull(),
|
||||
hoursweeky_plannedtowork: 0,
|
||||
endwork_estimate: tools.getDateNull(),
|
||||
themecolor: '',
|
||||
themebgcolor: '',
|
||||
groupId: '',
|
||||
respUsername: '',
|
||||
viceRespUsername: '',
|
||||
vice2RespUsername: '',
|
||||
tipovisu: 0
|
||||
}
|
||||
|
||||
return obj
|
||||
},
|
||||
|
||||
projs_dacompletare: (state: IProjectsState) => (id_parent: string, tipoproj: string): IProject[] => {
|
||||
// console.log('projs_dacompletare')
|
||||
if (state.projects) {
|
||||
// console.log('projs_dacompletare', state.projects)
|
||||
// @ts-ignore
|
||||
return this.getproj(state.projects, id_parent, tipoproj)
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
},
|
||||
|
||||
listaprojects: (state: IProjectsState) => (tipoproj: string): IMenuList[] => {
|
||||
if (state.projects) {
|
||||
console.log('listaprojects')
|
||||
// @ts-ignore
|
||||
const listaproj = this.getproj(state.projects, process.env.PROJECT_ID_MAIN, tipoproj)
|
||||
const myarr: IMenuList[] = []
|
||||
for (const proj of listaproj) {
|
||||
myarr.push({ nametranslate: '', description: proj.descr, idelem: proj._id })
|
||||
}
|
||||
console.log(' myarr', myarr, listaproj)
|
||||
return myarr
|
||||
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
},
|
||||
|
||||
listagerarchia: (state: IProjectsState) => (tipoproj: string, idparent: string): IMenuList[] => {
|
||||
if (state.projects) {
|
||||
// console.log('listagerarchia', idparent)
|
||||
const myarrgerarchia: IMenuList[] = []
|
||||
let myidparent = idparent
|
||||
let precmyparent = '-1'
|
||||
|
||||
while (state.projects && myidparent) {
|
||||
const proj = state.projects.find((rec) => rec._id === myidparent)
|
||||
if (proj) {
|
||||
myarrgerarchia.push({ nametranslate: '', description: proj.descr, idelem: proj._id })
|
||||
} else {
|
||||
break
|
||||
}
|
||||
if (myidparent === proj.id_parent || (!proj.id_parent && (precmyparent === myidparent)))
|
||||
break
|
||||
precmyparent = myidparent
|
||||
myidparent = proj.id_parent!
|
||||
}
|
||||
// console.log(' myarrgerarchia', myarrgerarchia)
|
||||
return myarrgerarchia.reverse()
|
||||
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
},
|
||||
|
||||
getDescrById: (state: IProjectsState) => (id: string): string => {
|
||||
if (id === process.env.PROJECT_ID_MAIN)
|
||||
return 'Projects'
|
||||
if (state.projects) {
|
||||
const itemtrov = state.projects.find((item) => item._id === id)
|
||||
if (!!itemtrov)
|
||||
return itemtrov.descr!
|
||||
}
|
||||
|
||||
return ''
|
||||
},
|
||||
|
||||
getRecordById: (state: IProjectsState) => (id: string): IProject | null => {
|
||||
// console.log('state.projects', state.projects)
|
||||
// console.log('find', state.projects.find((item) => item._id === id))
|
||||
if (state.projects) {
|
||||
return state.projects.find((item) => item._id === id)!
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
getifCanISeeProj: (state: IProjectsState) => (proj: IProject): boolean => {
|
||||
if ((proj === undefined) || (proj === null))
|
||||
return false
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
if (!!userStore.my) {
|
||||
|
||||
if (userStore.my._id === proj.userId) // If it's the owner
|
||||
return true
|
||||
|
||||
let myprojtocheck = proj
|
||||
if (proj.privacyread === Privacy.inherited) {
|
||||
// @ts-ignore
|
||||
myprojtocheck = this.getFirstInherited(proj, proj.id_parent, state)
|
||||
if (!myprojtocheck)
|
||||
return true
|
||||
}
|
||||
|
||||
console.log('privacyread', myprojtocheck.privacyread)
|
||||
|
||||
return (userStore.my._id === myprojtocheck.userId) || (myprojtocheck.privacyread === Privacy.all) ||
|
||||
(myprojtocheck.privacyread === Privacy.friends) && (userStore.IsMyFriend(myprojtocheck.userId!))
|
||||
|| ((myprojtocheck.privacyread === Privacy.mygroup) && (userStore.IsMyGroup(myprojtocheck.userId!)))
|
||||
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
getTipoVisuProj: (state: IProjectsState) => (proj: IProject): number => {
|
||||
if ((proj === undefined) || (proj === null))
|
||||
return TipoVisu.simplelist
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
if (!!userStore) {
|
||||
|
||||
let tipovisuproj = proj
|
||||
if (tipovisuproj.tipovisu === TipoVisu.inherited) {
|
||||
// @ts-ignore
|
||||
tipovisuproj = this.getFirstInheritedTipoVisu(proj, proj.id_parent, state)
|
||||
if (!tipovisuproj)
|
||||
return TipoVisu.simplelist
|
||||
}
|
||||
|
||||
return tipovisuproj.tipovisu!
|
||||
|
||||
} else {
|
||||
return TipoVisu.simplelist
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
CanIModifyPanelPrivacy: (state: IProjectsState) => (proj: IProject): boolean => {
|
||||
if ((proj === undefined) || (proj === null))
|
||||
return false
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
if (!!userStore) {
|
||||
|
||||
let myprojtocheck = proj
|
||||
if (proj.privacywrite === Privacy.inherited) {
|
||||
// @ts-ignore
|
||||
myprojtocheck = this.getFirstInherited(proj, proj.id_parent, state)
|
||||
if (!myprojtocheck)
|
||||
return true
|
||||
}
|
||||
|
||||
if (!!userStore)
|
||||
return (userStore.my._id === myprojtocheck.userId) || (myprojtocheck.privacywrite === Privacy.all) ||
|
||||
(myprojtocheck.privacywrite === Privacy.friends) && (userStore.IsMyFriend(myprojtocheck.userId!))
|
||||
|| ((myprojtocheck.privacywrite === Privacy.mygroup) && (userStore.IsMyGroup(myprojtocheck.userId!)))
|
||||
else
|
||||
return false
|
||||
}
|
||||
return false
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
actions: {
|
||||
|
||||
getFirstInherited(proj: IProject, idparent: string) {
|
||||
let myprojtocheck = null
|
||||
while (proj.privacyread === Privacy.inherited) {
|
||||
myprojtocheck = this.projects.find((rec) => rec._id === idparent)
|
||||
if (!myprojtocheck)
|
||||
return null
|
||||
|
||||
idparent = myprojtocheck.id_parent!
|
||||
proj = myprojtocheck
|
||||
}
|
||||
return myprojtocheck
|
||||
},
|
||||
|
||||
getFirstInheritedTipoVisu(proj: IProject, idparent: string) {
|
||||
let tipovisuproj = null
|
||||
while (!proj.tipovisu || proj.tipovisu <= 0) {
|
||||
tipovisuproj = this.projects.find((rec) => rec._id === idparent)
|
||||
if (!tipovisuproj)
|
||||
return null
|
||||
|
||||
idparent = tipovisuproj.id_parent!
|
||||
proj = tipovisuproj
|
||||
}
|
||||
return tipovisuproj!.tipovisu
|
||||
},
|
||||
|
||||
getarrByCategory(category: string) {
|
||||
if (!this.projects) {
|
||||
return []
|
||||
}
|
||||
return this.projects
|
||||
},
|
||||
|
||||
initcat() {
|
||||
const userStore = useUserStore()
|
||||
const rec = this.getRecordEmpty()
|
||||
rec.userId = userStore.my._id
|
||||
|
||||
return rec
|
||||
},
|
||||
|
||||
updateDataCalculated(projout: any, projin: any) {
|
||||
listFieldsUpdateCalculation.forEach((field) => {
|
||||
projout[field] = projin[field]
|
||||
})
|
||||
},
|
||||
|
||||
getproj(projects: any, idproj: any, tipoproj: string) {
|
||||
|
||||
let ris = null
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
if (tipoproj === RouteNames.myprojects)
|
||||
ris = projects.filter((proj: IProject) => (proj.id_parent === idproj) && (proj.userId === userStore.my._id))
|
||||
else if (tipoproj === RouteNames.projectsshared)
|
||||
ris = projects.filter((proj: IProject) => (proj.id_parent === idproj) && (proj.userId === userStore.my._id) && (proj.privacyread !== Privacy.onlyme))
|
||||
else if (tipoproj === RouteNames.projectsall)
|
||||
ris = projects.filter((proj: IProject) => (proj.id_parent === idproj) && (proj.userId !== userStore.my._id))
|
||||
else
|
||||
ris = projects.filter((proj: IProject) => (proj.id_parent === idproj))
|
||||
|
||||
if (ris)
|
||||
{ // @ts-ignore
|
||||
ris = ris.sort((a: IProject, b: IProject) => a.pos - b.pos)
|
||||
}
|
||||
// console.log('idproj', idproj, 'projects', projects, 'getproj', tipoproj, 'ris=', ris)
|
||||
|
||||
return ris
|
||||
},
|
||||
|
||||
createNewItem({ objproj, atfirst, categorySel }: { objproj: IProject, atfirst: boolean, categorySel: string }) {
|
||||
// console.log('createNewItem', objproj, 'cat=', categorySel, 'this.projects', this.projects)
|
||||
if (this.projects === undefined) {
|
||||
this.projects = []
|
||||
this.projects.push(objproj)
|
||||
console.log('push this.projects', this.projects)
|
||||
return
|
||||
}
|
||||
if (atfirst) {
|
||||
this.projects.unshift(objproj)
|
||||
} else {
|
||||
this.projects.push(objproj)
|
||||
}
|
||||
},
|
||||
|
||||
updateProject({ objproj }: { objproj: IProject }) {
|
||||
if (!!objproj) {
|
||||
// console.log('updateProject', objproj)
|
||||
const index = tools.getIndexById(this.projects, objproj._id)
|
||||
// console.log('index', index)
|
||||
if (index >= 0) {
|
||||
this.updateDataCalculated(this.projects[index], objproj)
|
||||
|
||||
// this.projects.splice(index, 1, objproj)
|
||||
// tools.notifyarraychanged(this.projects)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
deletemyitem(myitem: IProject) {
|
||||
// Find record
|
||||
const ind = tools.getIndexById(this.projects, myitem._id)
|
||||
|
||||
ApiTables.removeitemfromarray(this.projects, ind)
|
||||
},
|
||||
|
||||
async movemyitem({ myitemorig, myitemdest }: { myitemorig: IProject, myitemdest: IProject }) {
|
||||
const indorig = tools.getIndexById(this.projects, myitemorig._id)
|
||||
|
||||
this.projects.splice(indorig, 1)
|
||||
this.projects.push(myitemdest)
|
||||
|
||||
await this.modify({ myitem: myitemdest, field: 'id_parent' })
|
||||
},
|
||||
|
||||
async dbLoad({ checkPending, onlyiffirsttime }: { checkPending: boolean, onlyiffirsttime: boolean }) {
|
||||
|
||||
if (!static_data.functionality.ENABLE_PROJECTS_LOADING)
|
||||
return null
|
||||
|
||||
if (onlyiffirsttime) {
|
||||
if (this.projects.length > 0) {
|
||||
// if already set, then exit.
|
||||
return new Types.AxiosError(0, null, 0, '')
|
||||
}
|
||||
}
|
||||
|
||||
// if (userStore.my._id === '') {
|
||||
// return false // Login not made
|
||||
// }
|
||||
|
||||
// console.log('userStore.my', userStore.my)
|
||||
|
||||
// console.log('dbLoad', nametable, checkPending, 'userid=', userStore.my._id)
|
||||
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
const ris = await Api.SendReq('/projects/' + userStore.my._id, 'GET', null)
|
||||
.then((res) => {
|
||||
if (res.data.projects) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
this.projects = res.data.projects
|
||||
} else {
|
||||
this.projects = []
|
||||
}
|
||||
|
||||
this.showtype = parseInt(globalStore.getConfigStringbyId({
|
||||
id: costanti.CONFIG_ID_SHOW_TYPE_TODOS,
|
||||
default: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED
|
||||
}), 10)
|
||||
|
||||
if (process.env.DEBUG === '1') {
|
||||
console.log('dbLoad', 'this.projects', this.projects)
|
||||
}
|
||||
|
||||
return res
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error dbLoad', error)
|
||||
userStore.setErrorCatch(error)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error)
|
||||
})
|
||||
|
||||
ApiTables.aftercalling(ris, checkPending, nametable)
|
||||
},
|
||||
|
||||
async calculateHoursProjects({ projId, actualphase }: { projId: string, actualphase: string }) {
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/projects/calc/' + projId + '/' + actualphase, 'GET', null)
|
||||
.then((res) => {
|
||||
if (res.data.rec) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
return res.data.rec
|
||||
}
|
||||
return null
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error calculateHoursProjects', error)
|
||||
})
|
||||
|
||||
return ris
|
||||
},
|
||||
|
||||
async deleteItem({ idobj }: { idobj: any }) {
|
||||
console.log('deleteItem: KEY = ', idobj)
|
||||
|
||||
const myarr = this.getarrByCategory('')
|
||||
|
||||
const myobjtrov = tools.getElemById(myarr, idobj)
|
||||
|
||||
console.log('myobjtrov', myobjtrov.descr)
|
||||
|
||||
if (!!myobjtrov) {
|
||||
/*
|
||||
const myobjnext = tools.getElemPrevById(myarr, myobjtrov._id)
|
||||
|
||||
if (!!myobjnext) {
|
||||
myobjnext.pos = myobjtrov.pos + 1
|
||||
myobjnext.modified = true
|
||||
await modify( { myitem: myobjnext, field: 'pos' })
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
// ApiTables.table_DeleteRecord(nametable, myobjtrov, idobj)
|
||||
ApiTables.table_HideRecord(nametable, myobjtrov, idobj)
|
||||
}
|
||||
},
|
||||
|
||||
async dbInsert({ myobj, atfirst }: { myobj: IProject, atfirst: boolean}) {
|
||||
|
||||
const objproj = this.initcat()
|
||||
|
||||
objproj.descr = myobj.descr
|
||||
objproj.category = myobj.category
|
||||
objproj.id_parent = myobj.id_parent
|
||||
objproj.id_main_project = myobj.id_main_project
|
||||
objproj.typeproj = myobj.typeproj
|
||||
objproj.privacyread = myobj.privacyread
|
||||
objproj.privacywrite = myobj.privacywrite
|
||||
objproj.actualphase = myobj.actualphase
|
||||
objproj.tipovisu = myobj.tipovisu
|
||||
|
||||
let elemtochange: IProject = { }
|
||||
|
||||
const myarr = this.getarrByCategory(objproj.category!)
|
||||
|
||||
const tipoProj = ''
|
||||
|
||||
if (atfirst) {
|
||||
console.log('INSERT AT THE TOP')
|
||||
elemtochange = tools.getFirstList(myarr)
|
||||
objproj.pos = 10
|
||||
} else {
|
||||
console.log('INSERT AT THE BOTTOM')
|
||||
// INSERT AT THE BOTTOM , so GET LAST ITEM
|
||||
const lastelem = tools.getLastListNotCompleted(nametable, objproj.id_parent!, tipoProj)
|
||||
|
||||
objproj.pos = (!!lastelem) ? lastelem.pos + 10 : 10
|
||||
}
|
||||
objproj.modified = false
|
||||
|
||||
this.createNewItem({ objproj, atfirst, categorySel: objproj.category! }) // 1) Create record in Memory
|
||||
|
||||
const id = await globalroutines('write', nametable, objproj) // 2) Insert into the IndexedDb
|
||||
|
||||
let field = ''
|
||||
if (atfirst) { // update also the last elem
|
||||
if (!!elemtochange) {
|
||||
elemtochange.pos = objproj.pos
|
||||
console.log('elemtochange', elemtochange)
|
||||
field = 'pos'
|
||||
|
||||
// Modify the other record
|
||||
await this.modify({ myitem: elemtochange, field })
|
||||
}
|
||||
}
|
||||
|
||||
// 3) send to the Server
|
||||
await ApiTables.Sync_SaveItem(nametable, 'POST', objproj)
|
||||
|
||||
return id
|
||||
},
|
||||
|
||||
async modify({ myitem, field }: { myitem: any, field: any } ) {
|
||||
return ApiTables.table_ModifyRecord(nametable, myitem, listFieldsToChange, field)
|
||||
},
|
||||
|
||||
async swapElems(itemdragend: IDrag) {
|
||||
console.log('PROJECT swapElems', itemdragend, this.projects)
|
||||
|
||||
const myarr = this.projs_dacompletare(itemdragend.id_proj!, itemdragend.tipoproj!)
|
||||
|
||||
tools.swapGeneralElem(nametable, myarr, itemdragend, listFieldsToChange)
|
||||
|
||||
},
|
||||
|
||||
async ActionCutPaste(action: IAction) {
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
if (action.type === lists.MenuAction.CUT) {
|
||||
globalStore.lastaction = action
|
||||
} else if (action.type === lists.MenuAction.PASTE) {
|
||||
if (globalStore.lastaction.type === lists.MenuAction.CUT) {
|
||||
|
||||
// Change id_parent
|
||||
const orig_obj = this.getRecordById(globalStore.lastaction._id)
|
||||
const dest = this.getRecordById(action._id)
|
||||
|
||||
// console.log('dest', dest)
|
||||
|
||||
const dest_obj = tools.jsonCopy(orig_obj)
|
||||
|
||||
if (!!dest_obj) {
|
||||
dest_obj.id_parent = dest!._id
|
||||
dest_obj.id_main_project = dest!.id_main_project
|
||||
dest_obj.modified = true
|
||||
|
||||
globalStore.lastaction.type = 0
|
||||
|
||||
return this.movemyitem({ myitemorig: orig_obj!, myitemdest: dest_obj })
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
501
src/store/Todos.ts
Executable file
501
src/store/Todos.ts
Executable file
@@ -0,0 +1,501 @@
|
||||
import {
|
||||
ITodo,
|
||||
ITodosState,
|
||||
IParamTodo,
|
||||
IDrag,
|
||||
IAction
|
||||
} from 'model'
|
||||
|
||||
import Api from '@api'
|
||||
import { tools } from '@store/Modules/tools'
|
||||
import { lists } from './Modules/lists'
|
||||
import * as ApiTables from './Modules/ApiTables'
|
||||
import globalroutines from './../globalroutines/index'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
import objectId from '@src/js/objectId'
|
||||
import { costanti } from '@src/store/Modules/costanti'
|
||||
import * as Types from '@src/store/Api/ApiTypes'
|
||||
import { static_data } from '@src/db/static_data'
|
||||
import { defineStore } from "pinia"
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { useGlobalStore } from "@store/globalStore"
|
||||
import { toolsext } from "@store/Modules/toolsext"
|
||||
|
||||
const nametable = 'todos'
|
||||
|
||||
// import _ from 'lodash'
|
||||
|
||||
const state: ITodosState = {
|
||||
showtype: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED,
|
||||
todos: {},
|
||||
categories: [],
|
||||
// todos_changed: 1,
|
||||
reload_fromServer: 0,
|
||||
testpao: 'Test',
|
||||
insidePending: false,
|
||||
visuLastCompleted: 10
|
||||
}
|
||||
|
||||
const listFieldsToChange: string [] = ['descr', 'statustodo', 'category', 'expiring_at', 'priority', 'pos', 'enableExpiring', 'progress', 'phase', 'assigned_to_userId', 'hoursplanned', 'hoursworked', 'start_date', 'completed_at', 'themecolor', 'themebgcolor', 'assignedToUsers']
|
||||
|
||||
|
||||
export const useTodoStore = defineStore('Todos', {
|
||||
state: (): ITodosState => (
|
||||
{
|
||||
showtype: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED,
|
||||
todos: {},
|
||||
categories: [],
|
||||
// todos_changed: 1,
|
||||
reload_fromServer: 0,
|
||||
testpao: 'Test',
|
||||
insidePending: false,
|
||||
visuLastCompleted: 10,
|
||||
}),
|
||||
|
||||
getters: {
|
||||
getindexbycategory: (state: ITodosState) => (category: string): number => {
|
||||
if (state.categories) {
|
||||
return state.categories.indexOf(category)
|
||||
}
|
||||
return -1
|
||||
},
|
||||
|
||||
getRecordEmpty: (state: ITodosState) => (): ITodo => {
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
const tomorrow = tools.getDateNow()
|
||||
tomorrow.setDate(tomorrow.getDate() + 1)
|
||||
|
||||
const objtodo: ITodo = {
|
||||
// _id: tools.getDateNow().toISOString(), // Create NEW
|
||||
_id: objectId(),
|
||||
userId: userStore.my._id,
|
||||
descr: '',
|
||||
note: '',
|
||||
priority: tools.Priority.PRIORITY_NORMAL,
|
||||
statustodo: tools.Status.OPENED,
|
||||
created_at: tools.getDateNow(),
|
||||
modify_at: tools.getDateNow(),
|
||||
completed_at: tools.getDateNull(),
|
||||
category: '',
|
||||
expiring_at: tomorrow,
|
||||
enableExpiring: false,
|
||||
pos: 0,
|
||||
modified: false,
|
||||
progress: 0,
|
||||
progressCalc: 0,
|
||||
phase: 0,
|
||||
assigned_to_userId: '',
|
||||
hoursplanned: 0,
|
||||
hoursworked: 0,
|
||||
start_date: tools.getDateNull(),
|
||||
themecolor: 'blue',
|
||||
themebgcolor: 'white',
|
||||
assignedToUsers: []
|
||||
}
|
||||
// return this.copy(objtodo)
|
||||
return objtodo
|
||||
},
|
||||
|
||||
items_dacompletare: (state: ITodosState) => (cat: string): ITodo[] => {
|
||||
// console.log('items_dacompletare')
|
||||
// @ts-ignore
|
||||
const indcat: number = this.getindexbycategory(cat)
|
||||
let arrout = []
|
||||
// console.log('items_dacompletare', 'indcat', indcat, state.todos[indcat])
|
||||
if (indcat >= 0 && state.todos) {
|
||||
// @ts-ignore
|
||||
if (state.todos[indcat] ) {
|
||||
// @ts-ignore
|
||||
arrout = state.todos[indcat].filter((todo: ITodo) => todo.statustodo !== tools.Status.COMPLETED)
|
||||
}
|
||||
}
|
||||
|
||||
if (arrout)
|
||||
{ // @ts-ignore
|
||||
arrout = arrout.sort((a: ITodo, b: ITodo) => a.pos - b.pos)
|
||||
}
|
||||
|
||||
// return tools.mapSort(arrout)
|
||||
return arrout
|
||||
},
|
||||
|
||||
todos_completati: (state: ITodosState) => (cat: string): ITodo[] => {
|
||||
// @ts-ignore
|
||||
let indcat = this.getindexbycategory(cat)
|
||||
// console.log('todos_completati', cat, 'indcat=', indcat, 'this.categories=', this.categories)
|
||||
// @ts-ignore
|
||||
if (state.todos[indcat]) {
|
||||
let arrout = []
|
||||
if (state.showtype === costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED) { // Show only the first N completed
|
||||
// @ts-ignore
|
||||
arrout = state.todos[indcat].filter((todo: ITodo) => todo.statustodo === tools.Status.COMPLETED).slice(0, state.visuLastCompleted)
|
||||
} else if (state.showtype === costanti.ShowTypeTask.SHOW_ONLY_TOCOMPLETE) {
|
||||
arrout = []
|
||||
} else if (state.showtype === costanti.ShowTypeTask.SHOW_ALL) {
|
||||
// @ts-ignore
|
||||
arrout = state.todos[indcat].filter((todo: ITodo) => todo.statustodo === tools.Status.COMPLETED)
|
||||
} else {
|
||||
arrout = []
|
||||
}
|
||||
|
||||
if (arrout)
|
||||
{ // @ts-ignore
|
||||
arrout = arrout.sort((a: ITodo, b: ITodo) => a.pos - b.pos)
|
||||
}
|
||||
|
||||
// console.log('arrout', arrout)
|
||||
|
||||
return arrout
|
||||
// return tools.mapSort(arrout)
|
||||
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
},
|
||||
|
||||
doneTodosCount: (state: ITodosState) => (cat: string): number => {
|
||||
// @ts-ignore
|
||||
return this.todos_completati(cat).length
|
||||
},
|
||||
|
||||
TodosCount: (state: ITodosState) => (cat: string): number => {
|
||||
// @ts-ignore
|
||||
const indcat = this.getindexbycategory(cat)
|
||||
// @ts-ignore
|
||||
if (state.todos[indcat]) {
|
||||
// @ts-ignore
|
||||
return state.todos[indcat].length
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
},
|
||||
|
||||
getRecordById: (state: ITodosState) => (id: string, cat: string): ITodo => {
|
||||
// @ts-ignore
|
||||
const indcat = this.getindexbycategory(cat)
|
||||
if (state.todos) {
|
||||
// @ts-ignore
|
||||
return state.todos[indcat].find((item) => item._id === id)
|
||||
}
|
||||
return {}
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
|
||||
actions: {
|
||||
gettodosByCategory(category: string): any[] {
|
||||
const indcat = this.categories.indexOf(category)
|
||||
// @ts-ignore
|
||||
if (!this.todos[indcat]) {
|
||||
return []
|
||||
}
|
||||
// @ts-ignore
|
||||
return this.todos[indcat]
|
||||
},
|
||||
|
||||
initcat(): any {
|
||||
|
||||
const userStore = useUserStore()
|
||||
const rec = this.getRecordEmpty()
|
||||
rec.userId = userStore.my._id
|
||||
|
||||
return rec
|
||||
|
||||
},
|
||||
|
||||
findIndTodoById(data: IParamTodo) {
|
||||
const indcat = this.categories.indexOf(data.categorySel!)
|
||||
if (indcat >= 0) {
|
||||
// @ts-ignore
|
||||
return tools.getIndexById(this.todos[indcat], data.id)
|
||||
}
|
||||
return -1
|
||||
},
|
||||
|
||||
createNewItem({ objtodo, atfirst, categorySel }: { objtodo: ITodo, atfirst: boolean, categorySel: string }) {
|
||||
let indcat = state.categories.indexOf(categorySel)
|
||||
if (indcat === -1) {
|
||||
this.categories.push(categorySel)
|
||||
indcat = this.categories.indexOf(categorySel)
|
||||
}
|
||||
console.log('createNewItem', objtodo, 'cat=', categorySel, 'this.todos[indcat]', this.todos[indcat])
|
||||
if (this.todos[indcat] === undefined) {
|
||||
this.todos[indcat] = []
|
||||
this.todos[indcat].push(objtodo)
|
||||
console.log('push this.todos[indcat]', this.todos)
|
||||
return
|
||||
}
|
||||
if (atfirst) {
|
||||
this.todos[indcat].unshift(objtodo)
|
||||
} else {
|
||||
this.todos[indcat].push(objtodo)
|
||||
}
|
||||
|
||||
console.log('this.todos[indcat]', this.todos[indcat])
|
||||
|
||||
},
|
||||
|
||||
deletemyitem(myitem: ITodo) {
|
||||
// Find record
|
||||
const indcat = this.categories.indexOf(myitem.category!)
|
||||
const ind = this.findIndTodoById({ id: myitem._id, categorySel: myitem.category })
|
||||
|
||||
ApiTables.removeitemfromarray(this.todos[indcat], ind)
|
||||
},
|
||||
|
||||
async movemyitem({ myitemorig, myitemdest }: { myitemorig: ITodo, myitemdest: ITodo }) {
|
||||
|
||||
const indcat = this.categories.indexOf(myitemorig.category!)
|
||||
const indorig = tools.getIndexById(this.todos[indcat], myitemorig._id)
|
||||
let indcatdest = this.categories.indexOf(myitemdest.category!)
|
||||
|
||||
console.log('this.categories', this.categories)
|
||||
console.log('myitemdest', myitemdest)
|
||||
// console.log('indcat', indcat, 'indcatdest', indcatdest, 'indorig', indorig)
|
||||
|
||||
if (indcatdest === -1) {
|
||||
this.categories.push(myitemdest.category!)
|
||||
const newindcat = this.categories.indexOf(myitemdest.category!)
|
||||
this.todos[newindcat] = []
|
||||
indcatdest = newindcat
|
||||
}
|
||||
|
||||
this.todos[indcat].splice(indorig, 1)
|
||||
this.todos[indcatdest].push(myitemdest)
|
||||
|
||||
await this.modify({ myitem: myitemdest, field: 'category' })
|
||||
},
|
||||
|
||||
async dbLoad({ checkPending }: { checkPending: boolean }) {
|
||||
const globalStore = useGlobalStore()
|
||||
const userStore = useUserStore()
|
||||
|
||||
if (!static_data.functionality.ENABLE_PROJECTS_LOADING)
|
||||
return null
|
||||
|
||||
// console.log('dbLoad', nametable, checkPending, 'userid=', userStore.my._id)
|
||||
|
||||
// if (userStore.my._id === '') {
|
||||
// return new Types.AxiosError(0, null, 0, '')
|
||||
// }
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/todos/' + userStore.my._id, 'GET', null)
|
||||
.then((res) => {
|
||||
if (res.data.todos) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
this.todos = res.data.todos
|
||||
this.categories = res.data.categories
|
||||
} else {
|
||||
this.todos = [[]]
|
||||
}
|
||||
|
||||
this.showtype = parseInt(globalStore.getConfigStringbyId({
|
||||
id: costanti.CONFIG_ID_SHOW_TYPE_TODOS,
|
||||
default: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED
|
||||
}), 10)
|
||||
|
||||
// console.log('ARRAY TODOS = ', this.todos)
|
||||
if (process.env.DEBUG === '1') {
|
||||
// console.log('dbLoad', 'this.todos', this.todos, 'this.categories', this.categories)
|
||||
}
|
||||
|
||||
return res
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error dbLoad', error)
|
||||
userStore.setErrorCatch(error)
|
||||
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error)
|
||||
})
|
||||
|
||||
ApiTables.aftercalling(ris, checkPending, 'categories')
|
||||
|
||||
return ris
|
||||
},
|
||||
|
||||
async calculateHoursTodo({ todoId }: { todoId: string }) {
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/todos/calc/' + todoId, 'GET', null)
|
||||
.then((res) => {
|
||||
if (res.data.rec) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
return res.data.rec
|
||||
}
|
||||
return null
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error calculateHoursTodo', error)
|
||||
})
|
||||
|
||||
return ris
|
||||
},
|
||||
|
||||
async deleteItemtodo({ cat, idobj }: { cat: string, idobj: string }) {
|
||||
console.log('deleteItemtodo: KEY = ', idobj)
|
||||
|
||||
const myarr = this.gettodosByCategory(cat)
|
||||
|
||||
const myobjtrov = tools.getElemById(myarr, idobj)
|
||||
if (!!myobjtrov) {
|
||||
|
||||
console.log('myobjtrov', myobjtrov.descr)
|
||||
|
||||
if (!!myobjtrov) {
|
||||
/*
|
||||
const myobjnext = tools.getElemPrevById(myarr, myobjtrov._id)
|
||||
|
||||
if (!!myobjnext) {
|
||||
myobjnext.pos = myobjtrov.pos + 1
|
||||
myobjnext.modified = true
|
||||
await modify( { myitem: myobjnext, field: 'pos' })
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
ApiTables.table_HideRecord(nametable, myobjtrov, idobj)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async dbInsert({ myobj, atfirst }: { myobj: ITodo, atfirst: boolean }) {
|
||||
|
||||
const objtodo = this.initcat()
|
||||
|
||||
objtodo.descr = myobj.descr
|
||||
objtodo.category = myobj.category
|
||||
|
||||
const tipoProj = '' //++Todo: ?? nuovo tipoProj ?
|
||||
|
||||
let elemtochange: ITodo = {}
|
||||
|
||||
const myarr = this.gettodosByCategory(objtodo.category)
|
||||
|
||||
if (atfirst) {
|
||||
console.log('INSERT AT THE TOP')
|
||||
elemtochange = tools.getFirstList(myarr)
|
||||
objtodo.pos = 10
|
||||
} else {
|
||||
console.log('INSERT AT THE BOTTOM')
|
||||
// INSERT AT THE BOTTOM , so GET LAST ITEM
|
||||
const lastelem = tools.getLastListNotCompleted(nametable, objtodo.category, tipoProj)
|
||||
|
||||
objtodo.pos = (!!lastelem) ? lastelem.pos + 10 : 10
|
||||
}
|
||||
objtodo.modified = false
|
||||
|
||||
this.createNewItem({ objtodo, atfirst, categorySel: objtodo.category }) // 1) Create record in Memory
|
||||
|
||||
const id = await globalroutines('write', nametable, objtodo) // 2) Insert into the IndexedDb
|
||||
|
||||
let field = ''
|
||||
if (atfirst) { // update also the last elem
|
||||
if (!!elemtochange) {
|
||||
elemtochange.pos = objtodo.pos
|
||||
console.log('elemtochange', elemtochange)
|
||||
field = 'pos'
|
||||
|
||||
// Modify the other record
|
||||
await this.modify({ myitem: elemtochange, field })
|
||||
}
|
||||
}
|
||||
|
||||
// 3) send to the Server
|
||||
return ApiTables.Sync_SaveItem(nametable, 'POST', objtodo)
|
||||
.then((ris) => {
|
||||
// *** Check if need to be moved because of the --- Priority Ordering --- ...
|
||||
|
||||
const indelem = tools.getIndexById(myarr, objtodo._id)
|
||||
let itemdragend
|
||||
if (atfirst) {
|
||||
// Check the second item, if it's different priority, then move to the first position of the priority
|
||||
const secondindelem = indelem + 1
|
||||
if (tools.isOkIndex(myarr, secondindelem)) {
|
||||
const secondelem = tools.getElemByIndex(myarr, secondindelem)
|
||||
if (secondelem.priority !== objtodo.priority) {
|
||||
itemdragend = {
|
||||
field: 'priority',
|
||||
idelemtochange: objtodo._id,
|
||||
prioritychosen: objtodo.priority,
|
||||
category: objtodo.category,
|
||||
atfirst
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// get previous of the last
|
||||
const prevlastindelem = indelem - 1
|
||||
if (tools.isOkIndex(myarr, prevlastindelem)) {
|
||||
const prevlastelem = tools.getElemByIndex(myarr, prevlastindelem)
|
||||
if (prevlastelem.priority !== objtodo.priority) {
|
||||
itemdragend = {
|
||||
field: 'priority',
|
||||
idelemtochange: objtodo._id,
|
||||
prioritychosen: objtodo.priority,
|
||||
category: objtodo.category,
|
||||
atfirst
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (itemdragend) {
|
||||
this.swapElems(itemdragend)
|
||||
}
|
||||
return ris
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
async modify({ myitem, field }: { myitem: any, field: any }) {
|
||||
return ApiTables.table_ModifyRecord(nametable, myitem, listFieldsToChange, field)
|
||||
},
|
||||
|
||||
async swapElems(itemdragend: IDrag) {
|
||||
// console.log('TODOS swapElems', itemdragend, this.todos, this.categories)
|
||||
|
||||
const cat = itemdragend.category
|
||||
const indcat = this.categories.indexOf(cat!)
|
||||
// @ts-ignore
|
||||
const myarr = this.todos[indcat]
|
||||
|
||||
tools.swapGeneralElem(nametable, myarr, itemdragend, listFieldsToChange)
|
||||
|
||||
},
|
||||
|
||||
async ActionCutPaste(action: IAction) {
|
||||
console.log('ActionCutPaste', action)
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
if (action.type === lists.MenuAction.CUT) {
|
||||
globalStore.lastaction = action
|
||||
} else if (action.type === lists.MenuAction.PASTE) {
|
||||
if (globalStore.lastaction.type === lists.MenuAction.CUT) {
|
||||
|
||||
// Change id_parent
|
||||
const orig_obj = this.getRecordById(globalStore.lastaction._id, globalStore.lastaction.cat!)
|
||||
// const dest = this.getRecordById(action._id, action.cat)
|
||||
|
||||
console.log('action', action, 'orig_obj', orig_obj)
|
||||
|
||||
const dest_obj = tools.jsonCopy(orig_obj)
|
||||
|
||||
if (!!dest_obj) {
|
||||
dest_obj.category = action._id
|
||||
dest_obj.modified = true
|
||||
dest_obj.pos = 1
|
||||
|
||||
globalStore.lastaction.type = 0
|
||||
|
||||
return await this.movemyitem({ myitemorig: orig_obj, myitemdest: dest_obj })
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
})
|
||||
@@ -130,6 +130,9 @@ export const useUserStore = defineStore('UserStore', {
|
||||
getServerCode: (state: IUserState): number => (state.servercode ? state.servercode : 0),
|
||||
|
||||
getNameSurnameByUserId: (state: IUserState) => (userId: string): string => {
|
||||
// @ts-ignore
|
||||
const prova: number = this.getServerCode(state)
|
||||
|
||||
// @ts-ignore
|
||||
const user = this.getUserByUserId(state, userId)
|
||||
if (user) return `${user.name} ${user.surname}`
|
||||
@@ -143,6 +146,23 @@ export const useUserStore = defineStore('UserStore', {
|
||||
return `(${username})`
|
||||
},
|
||||
|
||||
getUsersList: (mystate: IUserState) => {
|
||||
return mystate.usersList
|
||||
},
|
||||
|
||||
IsMyFriend: (mystate: IUserState) => (userIdOwner: string): boolean => {
|
||||
// ++TODO Check if userIdOwner is my friend
|
||||
// userIdOwner is my friend ?
|
||||
return true
|
||||
},
|
||||
|
||||
IsMyGroup: (mystate: IUserState) => (userIdOwner: string): boolean => {
|
||||
// ++TODO Check if userIdOwner is on my groups
|
||||
// userIdOwner is on my groups ?
|
||||
return true
|
||||
},
|
||||
|
||||
|
||||
getUserByUserId: (state: IUserState) => (userId: string): IUserFields | null => {
|
||||
// Check if is this User!
|
||||
if (state.my._id === userId) return state.my
|
||||
@@ -500,7 +520,7 @@ export const useUserStore = defineStore('UserStore', {
|
||||
// console.log('autologin _id STATE ', this._id)
|
||||
|
||||
// return true
|
||||
} catch (e) {
|
||||
} catch (e: any) {
|
||||
console.error('ERR autologin ', e.message)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import { shared_consts } from '@src/common/shared_vuejs'
|
||||
const stateConnDefault = 'online'
|
||||
|
||||
export const useGlobalStore = defineStore('GlobalStore', {
|
||||
// @ts-ignore
|
||||
state: (): IGlobalState => ({
|
||||
finishLoading: false,
|
||||
conta: 0,
|
||||
@@ -86,8 +85,23 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
}),
|
||||
|
||||
getters: {
|
||||
// conta: (state: IGlobalState) => { state.conta },
|
||||
// listatodo: (state: IGlobalState) => { state.listatodo },
|
||||
// category: (state: IGlobalState) => { state.category },
|
||||
|
||||
isNewVersionAvailable(state: IGlobalState) {
|
||||
testpao1_getter_contatore: (state: IGlobalState) => (param1: number) => state.testp1.contatore + 100 + param1,
|
||||
testpao1_getter_array: (state: IGlobalState) => (param1: number) => state.testp1.mioarray.filter((item) => item).map((item) => item.valore),
|
||||
|
||||
getConfigbyId: (state: IGlobalState) => (id: string) => state.arrConfig.find((item) => item._id === id),
|
||||
getConfigStringbyId: (state: IGlobalState) => (params: any) => {
|
||||
const config = state.arrConfig.find((item) => item._id === params.id)
|
||||
if (config) {
|
||||
return config.value
|
||||
} else {
|
||||
return params.default
|
||||
}
|
||||
},
|
||||
isNewVersionAvailable: (state: IGlobalState) => {
|
||||
// console.log('cfgServer', cfgServer)
|
||||
const serversrec = state.cfgServer.find((x) => (x.chiave === toolsext.SERVKEY_VERS) && (x.idapp === process.env.APP_ID))
|
||||
// console.log('Record ', serversrec)
|
||||
|
||||
@@ -20,9 +20,15 @@ export const useTestStore = defineStore({
|
||||
return (rec.lang === toolsext.getLocale(false) || toolsext.getLocale() === '')
|
||||
},
|
||||
|
||||
prova2(): boolean {
|
||||
return this.finishLoading
|
||||
prova1: (state: ITest) => (myval: number): boolean => {
|
||||
return (myval > 1)
|
||||
},
|
||||
|
||||
prova2: (): boolean => {
|
||||
// @ts-ignore
|
||||
return this.prova1(2)
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
||||
Reference in New Issue
Block a user