Cut/Paste project and todos

This commit is contained in:
Paolo Arena
2019-04-29 01:01:31 +02:00
parent 2ba3cd6b3f
commit d6d527e1a8
14 changed files with 218 additions and 71 deletions

View File

@@ -51,7 +51,12 @@ const state: IGlobalState = {
downloading_server: 0,
downloading_indexeddb: 0
},
arrConfig: []
arrConfig: [],
lastaction: {
table: '',
type: 0,
_id: 0
}
}
async function getConfig(id) {

View File

@@ -18,19 +18,15 @@ const stateglob: IProjectsState = {
showtype: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED,
projects: [],
insidePending: false,
visuLastCompleted: 10,
action: {
type: 0,
_id: ''
}
visuLastCompleted: 10
}
const listFieldsToChange: string [] = ['descr', 'longdescr', 'hoursplanned', 'hoursworked', 'id_parent', 'statusproj',
const listFieldsToChange: string [] = ['descr', 'longdescr', 'hoursplanned', 'hoursleft', 'hoursworked', 'id_parent', 'statusproj',
'category', 'expiring_at', 'priority', 'id_prev', 'pos', 'enableExpiring', 'progressCalc', 'live_url', 'test_url',
'begin_development', 'begin_test', 'actualphase', 'totalphases', 'hoursweeky_plannedtowork', 'endwork_estimate',
'privacyread', 'privacywrite', 'id_main_project', 'typeproj', 'favourite']
const listFieldsUpdateCalculation: string [] = ['hoursplanned', 'hoursworked', 'progressCalc', 'endwork_estimate']
const listFieldsUpdateCalculation: string [] = ['hoursplanned', 'hoursleft', 'hoursworked', 'progressCalc', 'endwork_estimate']
const b = storeBuilder.module<IProjectsState>('Projects', stateglob)
const stateGetter = b.state()
@@ -92,13 +88,14 @@ namespace Getters {
actualphase: 1,
hoursworked: 0,
hoursplanned: 0,
hoursleft: 0,
progressCalc: 0,
privacyread: 'onlyme',
privacywrite: 'onlyme',
begin_development: tools.getDateNull(),
begin_test: tools.getDateNull(),
hoursweeky_plannedtowork: 0,
endwork_estimate: tools.getDateNull(),
endwork_estimate: tools.getDateNull()
}
return obj
@@ -247,9 +244,6 @@ namespace Mutations {
async function movemyitem(state: IProjectsState, { myitemorig, myitemdest } ) {
const indorig = tools.getIndexById(state.projects, myitemorig._id)
// console.log('myitemorig', myitemorig, 'indorig', indorig)
// console.log('myitemdest', myitemdest)
state.projects.splice(indorig, 1)
state.projects.push(myitemdest)
@@ -399,13 +393,13 @@ namespace Actions {
async function ActionCutPaste(context, action: IAction) {
if (action.type === tools.MenuAction.CUT)
stateglob.action = action
else if (action.type === tools.MenuAction.PASTE) {
if (stateglob.action.type === tools.MenuAction.CUT) {
if (action.type === tools.MenuAction.CUT) {
GlobalStore.state.lastaction = action
} else if (action.type === tools.MenuAction.PASTE) {
if (GlobalStore.state.lastaction.type === tools.MenuAction.CUT) {
// Change id_parent
const orig_obj = Getters.getters.getRecordById(stateglob.action._id)
const orig_obj = Getters.getters.getRecordById(GlobalStore.state.lastaction._id)
const dest = Getters.getters.getRecordById(action._id)
// console.log('dest', dest)
@@ -418,13 +412,12 @@ namespace Actions {
dest_obj.modified = true
dest_obj.id_prev = null
await Mutations.mutations.movemyitem({ myitemorig: orig_obj, myitemdest: dest_obj })
}
GlobalStore.state.lastaction.type = 0
stateglob.action.type = 0
return await Mutations.mutations.movemyitem({ myitemorig: orig_obj, myitemdest: dest_obj })
}
}
}
return true
}
export const actions = {

View File

@@ -11,6 +11,7 @@ import { serv_constants } from '@src/store/Modules/serv_constants'
import { GetterTree } from 'vuex'
import objectId from '@src/js/objectId'
import { costanti } from '@src/store/Modules/costanti'
import { IAction } from '@src/model'
const nametable = 'todos'
@@ -46,7 +47,7 @@ function gettodosByCategory(category: string): [] {
function initcat() {
let rec = Getters.getters.getRecordEmpty()
const rec = Getters.getters.getRecordEmpty()
rec.userId = UserStore.state.userId
return rec
@@ -54,7 +55,7 @@ function initcat() {
}
namespace Getters {
const getRecordEmpty = b.read((state: ITodosState) => (): ITodo => {
const getRecordEmpty = b.read((stateparamf: ITodosState) => (): ITodo => {
const tomorrow = tools.getDateNow()
tomorrow.setDate(tomorrow.getDate() + 1)
@@ -81,32 +82,32 @@ namespace Getters {
assigned_to_userId: '',
hoursplanned: 0,
hoursworked: 0,
start_date: tools.getDateNull(),
start_date: tools.getDateNull()
}
// return this.copy(objtodo)
return objtodo
}, 'getRecordEmpty')
const items_dacompletare = b.read((state: ITodosState) => (cat: string): ITodo[] => {
const items_dacompletare = b.read((stateparam: ITodosState) => (cat: string): ITodo[] => {
const indcat = getindexbycategory(cat)
// console.log('items_dacompletare', 'indcat', indcat, state.todos[indcat])
if (state.todos[indcat]) {
return state.todos[indcat].filter((todo) => todo.statustodo !== tools.Status.COMPLETED)
// console.log('items_dacompletare', 'indcat', indcat, stateparam.todos[indcat])
if (stateparam.todos[indcat]) {
return stateparam.todos[indcat].filter((todo) => todo.statustodo !== tools.Status.COMPLETED)
} else {
return []
}
}, 'items_dacompletare')
const todos_completati = b.read((state: ITodosState) => (cat: string): ITodo[] => {
const todos_completati = b.read((stateparam: ITodosState) => (cat: string): ITodo[] => {
const indcat = getindexbycategory(cat)
if (state.todos[indcat]) {
if (state.showtype === costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED) { // Show only the first N completed
return state.todos[indcat].filter((todo) => todo.statustodo === tools.Status.COMPLETED).slice(0, state.visuLastCompleted)
if (stateparam.todos[indcat]) {
if (stateparam.showtype === costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED) { // Show only the first N completed
return stateparam.todos[indcat].filter((todo) => todo.statustodo === tools.Status.COMPLETED).slice(0, stateparam.visuLastCompleted)
}
else if (state.showtype === costanti.ShowTypeTask.SHOW_ONLY_TOCOMPLETE) {
else if (stateparam.showtype === costanti.ShowTypeTask.SHOW_ONLY_TOCOMPLETE) {
return []
}
else if (state.showtype === costanti.ShowTypeTask.SHOW_ALL) {
return state.todos[indcat].filter((todo) => todo.statustodo === tools.Status.COMPLETED)
else if (stateparam.showtype === costanti.ShowTypeTask.SHOW_ALL) {
return stateparam.todos[indcat].filter((todo) => todo.statustodo === tools.Status.COMPLETED)
}
else {
return []
@@ -116,22 +117,22 @@ namespace Getters {
}
}, 'todos_completati')
const doneTodosCount = b.read((state: ITodosState) => (cat: string): number => {
const doneTodosCount = b.read((stateparam: ITodosState) => (cat: string): number => {
return getters.todos_completati(cat).length
}, 'doneTodosCount')
const TodosCount = b.read((state: ITodosState) => (cat: string): number => {
const TodosCount = b.read((stateparam: ITodosState) => (cat: string): number => {
const indcat = getindexbycategory(cat)
if (state.todos[indcat]) {
return state.todos[indcat].length
if (stateparam.todos[indcat]) {
return stateparam.todos[indcat].length
} else {
return 0
}
}, 'TodosCount')
const getRecordById = b.read((state: ITodosState) => (id: string, cat: string): ITodo => {
const getRecordById = b.read((stateparam: ITodosState) => (id: string, cat: string): ITodo => {
const indcat = getindexbycategory(cat)
if (state.todos) {
return state.todos[indcat].find((item) => item._id === id)
if (stateparam.todos) {
return stateparam.todos[indcat].find((item) => item._id === id)
}
return null
}, 'getRecordById')
@@ -160,49 +161,73 @@ namespace Getters {
namespace Mutations {
function findIndTodoById(state: ITodosState, data: IParamTodo) {
const indcat = state.categories.indexOf(data.categorySel)
function findIndTodoById(stateparam: ITodosState, data: IParamTodo) {
const indcat = stateparam.categories.indexOf(data.categorySel)
if (indcat >= 0) {
return tools.getIndexById(state.todos[indcat], data.id)
return tools.getIndexById(stateparam.todos[indcat], data.id)
}
return -1
}
function createNewItem(state: ITodosState, { objtodo, atfirst, categorySel }) {
let indcat = state.categories.indexOf(categorySel)
if (indcat == -1) {
state.categories.push(categorySel)
indcat = state.categories.indexOf(categorySel)
function createNewItem(stateparam: ITodosState, { objtodo, atfirst, categorySel }) {
let indcat = stateparam.categories.indexOf(categorySel)
if (indcat === -1) {
stateparam.categories.push(categorySel)
indcat = stateparam.categories.indexOf(categorySel)
}
console.log('createNewItem', objtodo, 'cat=', categorySel, 'state.todos[indcat]', state.todos[indcat])
if (state.todos[indcat] === undefined) {
state.todos[indcat] = []
state.todos[indcat].push(objtodo)
console.log('push state.todos[indcat]', state.todos)
console.log('createNewItem', objtodo, 'cat=', categorySel, 'stateparam.todos[indcat]', stateparam.todos[indcat])
if (stateparam.todos[indcat] === undefined) {
stateparam.todos[indcat] = []
stateparam.todos[indcat].push(objtodo)
console.log('push stateparam.todos[indcat]', stateparam.todos)
return
}
if (atfirst) {
state.todos[indcat].unshift(objtodo)
stateparam.todos[indcat].unshift(objtodo)
}
else {
state.todos[indcat].push(objtodo)
stateparam.todos[indcat].push(objtodo)
}
console.log('state.todos[indcat]', state.todos[indcat])
console.log('stateparam.todos[indcat]', stateparam.todos[indcat])
}
function deletemyitem(state: ITodosState, myitem: ITodo) {
function deletemyitem(stateparam: ITodosState, myitem: ITodo) {
// Find record
const indcat = state.categories.indexOf(myitem.category)
const ind = findIndTodoById(state, { id: myitem._id, categorySel: myitem.category })
const indcat = stateparam.categories.indexOf(myitem.category)
const ind = findIndTodoById(stateparam, { id: myitem._id, categorySel: myitem.category })
ApiTables.removeitemfromarray(state.todos[indcat], ind)
ApiTables.removeitemfromarray(stateparam.todos[indcat], ind)
}
async function movemyitem(stateparam: ITodosState, { myitemorig, myitemdest } ) {
const indcat = stateparam.categories.indexOf(myitemorig.category)
const indorig = tools.getIndexById(stateparam.todos[indcat], myitemorig._id)
let indcatdest = stateparam.categories.indexOf(myitemdest.category)
console.log('stateparam.categories', stateparam.categories)
console.log('myitemdest', myitemdest)
console.log('indcat', indcat, 'indcatdest', indcatdest, 'indorig', indorig)
if (indcatdest === -1) {
stateparam.categories.push(myitemdest.category)
const newindcat = stateparam.categories.indexOf(myitemdest.category)
stateparam.todos[newindcat] = []
indcatdest = newindcat
}
stateparam.todos[indcat].splice(indorig, 1)
stateparam.todos[indcatdest].push(myitemdest)
await Actions.actions.modify({ myitem: myitemdest, field: 'category' })
}
export const mutations = {
deletemyitem: b.commit(deletemyitem),
createNewItem: b.commit(createNewItem)
createNewItem: b.commit(createNewItem),
movemyitem: b.commit(movemyitem)
}
}
@@ -373,12 +398,42 @@ namespace Actions {
}
async function ActionCutPaste(context, action: IAction) {
console.log('ActionCutPaste', action)
if (action.type === tools.MenuAction.CUT) {
GlobalStore.state.lastaction = action
} else if (action.type === tools.MenuAction.PASTE) {
if (GlobalStore.state.lastaction.type === tools.MenuAction.CUT) {
// Change id_parent
const orig_obj = Getters.getters.getRecordById(GlobalStore.state.lastaction._id, GlobalStore.state.lastaction.cat)
// const dest = Getters.getters.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.id_prev = null
GlobalStore.state.lastaction.type = 0
return await Mutations.mutations.movemyitem({ myitemorig: orig_obj, myitemdest: dest_obj })
}
}
}
}
export const actions = {
dbLoad: b.dispatch(dbLoad),
swapElems: b.dispatch(swapElems),
deleteItemtodo: b.dispatch(deleteItemtodo),
dbInsert: b.dispatch(dbInsert),
modify: b.dispatch(modify)
modify: b.dispatch(modify),
ActionCutPaste: b.dispatch(ActionCutPaste)
}
}

View File

@@ -14,6 +14,8 @@ export interface INotify {
}
export const tools = {
projects: 'projects',
todos: 'todos',
EMPTY: 0,
CALLING: 10,
OK: 20,
@@ -365,8 +367,16 @@ export const tools = {
menuPopupTodo:
{
it: [
{
id: 5,
disable: false,
label: 'Taglia',
value: 71, // CUT
icon: 'undo'
},
{
id: 10,
disable: false,
label: '',
value: 120, // PROGRESS_BAR
icon: 'rowing',
@@ -374,6 +384,7 @@ export const tools = {
},
{
id: 20,
disable: false,
label: 'Imposta Priorità',
value: 130, // PRIORITY
icon: 'rowing',
@@ -381,6 +392,7 @@ export const tools = {
},
{
id: 30,
disable: false,
label: 'Completato',
value: 110, // COMPLETED
icon: 'check_circle',
@@ -388,6 +400,7 @@ export const tools = {
},
{
id: 40,
disable: false,
label: 'Imposta Scadenza',
value: 101, // TOGGLE_EXPIRING
icon: 'date_range',
@@ -395,6 +408,7 @@ export const tools = {
},
{
id: 50,
disable: false,
label: 'Elimina',
value: 100, // DELETE
icon: 'delete',
@@ -403,8 +417,16 @@ export const tools = {
],
es:
[
{
id: 5,
disable: false,
label: 'Cortar',
value: 71, // CUT
icon: 'undo'
},
{
id: 10,
disable: false,
label: '',
value: 120, // PROGRESS_BAR
icon: 'rowing',
@@ -412,6 +434,7 @@ export const tools = {
},
{
id: 20,
disable: false,
label: 'Establecer Prioridad',
value: 130, // PRIORITY
icon: 'rowing',
@@ -419,6 +442,7 @@ export const tools = {
},
{
id: 30,
disable: false,
label: 'Completado',
value: 110, // COMPLETED
icon: 'check_circle',
@@ -426,6 +450,7 @@ export const tools = {
},
{
id: 40,
disable: false,
label: 'Establecer expiración',
value: 101, // TOGGLE_EXPIRING
icon: 'date_range',
@@ -433,6 +458,7 @@ export const tools = {
},
{
id: 50,
disable: false,
label: 'Borrar',
value: 100, // DELETE
icon: 'delete',
@@ -441,8 +467,16 @@ export const tools = {
],
enUs:
[
{
id: 5,
disable: false,
label: 'Cut',
value: 71, // CUT
icon: 'undo'
},
{
id: 10,
disable: false,
label: '',
value: 120, // PROGRESS_BAR
icon: 'check_circle',
@@ -450,6 +484,7 @@ export const tools = {
},
{
id: 20,
disable: false,
label: 'Set Priority',
value: 130, // PRIORITY
icon: 'high_priority',
@@ -457,6 +492,7 @@ export const tools = {
},
{
id: 30,
disable: false,
label: 'Completed',
value: 110, // COMPLETED
icon: 'check_circle',
@@ -464,6 +500,7 @@ export const tools = {
},
{
id: 40,
disable: false,
label: 'Set Expiring',
value: 101, // TOGGLE_EXPIRING
icon: 'date_range',
@@ -471,6 +508,7 @@ export const tools = {
},
{
id: 50,
disable: false,
label: 'Delete',
value: 100, // DELETE
icon: 'trash',
@@ -484,18 +522,21 @@ export const tools = {
it: [
{
id: 5,
disable: false,
label: 'Taglia',
value: 71, // CUT
icon: 'undo'
},
{
id: 10,
disable: false,
label: 'Modifica',
value: 160, // EDIT
icon: 'create'
},
{
id: 40,
disable: false,
label: 'Imposta Scadenza',
value: 101, // TOGGLE_EXPIRING
icon: 'date_range',
@@ -503,6 +544,7 @@ export const tools = {
},
{
id: 50,
disable: false,
label: 'Elimina',
value: 100, // DELETE
icon: 'delete',
@@ -513,18 +555,21 @@ export const tools = {
[
{
id: 5,
disable: false,
label: 'Cortar',
value: 71, // CUT
icon: 'undo'
},
{
id: 10,
disable: false,
label: 'Editar',
value: 160, // EDIT
icon: 'create'
},
{
id: 40,
disable: false,
label: 'Establecer expiración',
value: 101, // TOGGLE_EXPIRING
icon: 'date_range',
@@ -532,6 +577,7 @@ export const tools = {
},
{
id: 50,
disable: false,
label: 'Borrar',
value: 100, // DELETE
icon: 'delete',
@@ -542,18 +588,21 @@ export const tools = {
[
{
id: 5,
disable: false,
label: 'Cut',
value: 71, // CUT
icon: 'undo'
},
{
id: 10,
disable: false,
label: 'Edit',
value: 160, // EDIT
icon: 'create'
},
{
id: 40,
disable: false,
label: 'Set Expiring',
value: 101, // TOGGLE_EXPIRING
icon: 'date_range',
@@ -561,6 +610,7 @@ export const tools = {
},
{
id: 50,
disable: false,
label: 'Delete',
value: 100, // DELETE
icon: 'trash',
@@ -574,6 +624,7 @@ export const tools = {
it: [
{
id: 10,
disable: false,
label: 'Mostra Task',
value: 150, // SHOW_TASK
icon: 'rowing'
@@ -583,6 +634,7 @@ export const tools = {
[
{
id: 10,
disable: false,
label: 'Mostrar Tareas',
value: 150,
icon: 'rowing'
@@ -592,6 +644,7 @@ export const tools = {
[
{
id: 10,
disable: false,
label: 'Show Task',
value: 150,
icon: 'rowing'