Files
freeplanet/src/store/Modules/tools.ts

469 lines
9.2 KiB
TypeScript
Raw Normal View History

2019-03-22 15:32:32 +01:00
import { UserStore } from '@store'
2019-03-13 01:53:53 +01:00
import globalroutines from './../../globalroutines/index'
import { costanti } from './costanti'
import Quasar from 'quasar'
2019-03-13 13:40:17 +01:00
export interface INotify {
color?: string | 'primary'
textColor?: string
icon?: string | ''
}
export const tools = {
EMPTY: 0,
CALLING: 10,
OK: 20,
ERR_GENERICO: -1,
ERR_SERVERFETCH: -2,
ERR_AUTHENTICATION: -5,
DUPLICATE_EMAIL_ID: 11000,
DUPLICATE_USERNAME_ID: 11100,
arrLangUsed: ['enUs', 'it', 'es'],
SERVKEY_VERS: 'vers',
localStorage: {
verified_email: 'vf',
2019-02-13 18:48:30 +01:00
wasAlreadySubOnDb: 'sb',
categorySel: 'cs',
isLogged: 'ilog',
expirationDate: 'expdate',
leftDrawerOpen: 'ldo',
userId: 'uid',
token: 'tk',
2019-02-16 02:01:17 +01:00
username: 'uname',
lang: 'lg'
},
2019-03-22 18:49:38 +01:00
Priority: {
PRIORITY_HIGH: 2,
PRIORITY_NORMAL: 1,
PRIORITY_LOW: 0
},
MenuAction: {
DELETE: 100,
TOGGLE_EXPIRING: 101,
2019-01-29 00:48:04 +01:00
COMPLETED: 110,
PROGRESS_BAR: 120,
2019-03-04 17:28:29 +01:00
PRIORITY: 130,
2019-03-13 01:53:53 +01:00
SHOW_TASK: 150
},
selectPriority: {
2019-03-13 01:53:53 +01:00
it: [
{
id: 1,
label: 'Alta',
value: 2,
icon: 'expand_less'
},
{
id: 2,
label: 'Normale',
value: 1,
icon: 'remove'
},
{
id: 3,
label: 'Bassa',
value: 0,
icon: 'expand_more'
}],
2019-03-13 01:53:53 +01:00
es: [
2019-02-16 02:01:17 +01:00
{
id: 1,
label: 'Alta',
value: 2,
icon: 'expand_less'
},
{
id: 2,
label: 'Normal',
value: 1,
icon: 'remove'
},
{
id: 3,
label: 'Baja',
value: 0,
icon: 'expand_more'
}],
2019-03-13 01:53:53 +01:00
enUs: [
2019-02-16 02:01:17 +01:00
{
id: 1,
label: 'High',
value: 2,
icon: 'expand_less'
},
{
id: 2,
label: 'Normal',
value: 1,
icon: 'remove'
},
{
id: 3,
label: 'Low',
value: 0,
icon: 'expand_more'
}],
2019-03-13 01:53:53 +01:00
de: [
{
id: 1,
label: 'High',
value: 2,
icon: 'expand_less'
},
{
id: 2,
label: 'Normal',
value: 1,
icon: 'remove'
},
{
id: 3,
label: 'Low',
value: 0,
icon: 'expand_more'
}]
},
INDEX_MENU_DELETE: 4,
menuPopupTodo: {
2019-03-13 01:53:53 +01:00
it: [
{
id: 10,
label: '',
2019-01-29 00:48:04 +01:00
value: 120, // PROGRESS_BAR
icon: 'rowing',
2019-01-29 00:48:04 +01:00
checked: true
},
{
id: 20,
label: 'Imposta Priorità',
value: 130, // PRIORITY
icon: 'rowing',
checked: false
},
{
id: 30,
label: 'Completato',
value: 110, // COMPLETED
icon: 'check_circle',
checked: true
},
{
id: 40,
label: 'Imposta Scadenza',
value: 101, // TOGGLE_EXPIRING
icon: 'date_range',
checked: true
},
{
id: 50,
2019-02-02 20:13:06 +01:00
label: 'Elimina',
value: 100, // DELETE
icon: 'delete',
checked: false
}
],
2019-03-13 01:53:53 +01:00
es: [
2019-02-16 02:01:17 +01:00
{
id: 10,
label: '',
value: 120, // PROGRESS_BAR
icon: 'rowing',
checked: true
},
{
id: 20,
label: 'Establecer Prioridad',
value: 130, // PRIORITY
icon: 'rowing',
checked: false
},
{
id: 30,
label: 'Completado',
value: 110, // COMPLETED
icon: 'check_circle',
checked: true
},
{
id: 40,
label: 'Establecer expiración',
value: 101, // TOGGLE_EXPIRING
icon: 'date_range',
checked: true
},
{
id: 50,
label: 'Borrar',
value: 100, // DELETE
icon: 'delete',
checked: false
}
],
2019-03-13 01:53:53 +01:00
enUs: [
{
id: 10,
label: '',
2019-01-29 00:48:04 +01:00
value: 120, // PROGRESS_BAR
icon: 'check_circle',
checked: true
},
{
id: 20,
label: 'Set Priority',
value: 130, // PRIORITY
icon: 'high_priority',
checked: false
},
{
id: 30,
label: 'Completed',
value: 110, // COMPLETED
icon: 'check_circle',
checked: true
},
{
id: 40,
label: 'Set Expiring',
value: 101, // TOGGLE_EXPIRING
icon: 'date_range',
checked: true
},
{
id: 50,
label: 'Delete',
value: 100, // DELETE
icon: 'trash',
checked: false
}
]
},
2019-03-04 17:28:29 +01:00
menuPopupConfigTodo: {
2019-03-13 01:53:53 +01:00
it: [
2019-03-04 17:28:29 +01:00
{
id: 10,
label: 'Mostra Task',
value: 150, // SHOW_TASK
2019-03-13 01:53:53 +01:00
icon: 'rowing'
}
2019-03-04 17:28:29 +01:00
],
2019-03-13 01:53:53 +01:00
es: [
2019-03-04 17:28:29 +01:00
{
id: 10,
label: 'Mostrar Tareas',
value: 150,
2019-03-13 01:53:53 +01:00
icon: 'rowing'
}
2019-03-04 17:28:29 +01:00
],
2019-03-13 01:53:53 +01:00
enUs: [
2019-03-04 17:28:29 +01:00
{
id: 10,
label: 'Show Task',
value: 150,
2019-03-13 01:53:53 +01:00
icon: 'rowing'
}
2019-03-04 17:28:29 +01:00
]
},
listOptionShowTask: {
2019-03-13 01:53:53 +01:00
it: [
2019-03-04 17:28:29 +01:00
{
id: 10,
label: 'Mostra gli ultimi N completati',
value: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED,
icon: 'rowing',
checked: true
},
{
id: 20,
label: 'Compiti da Completare',
value: costanti.ShowTypeTask.SHOW_ONLY_TOCOMPLETE,
icon: 'rowing',
checked: false
},
{
id: 30,
label: 'Tutti i compiti',
value: costanti.ShowTypeTask.SHOW_ALL,
icon: 'check_circle',
checked: true
}
],
2019-03-13 01:53:53 +01:00
es: [
2019-03-04 17:28:29 +01:00
{
id: 10,
label: 'Mostrar los ultimos N completados',
value: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED,
icon: 'rowing',
checked: true
},
{
id: 20,
label: 'Tareas para completar',
value: costanti.ShowTypeTask.SHOW_ONLY_TOCOMPLETE,
icon: 'rowing',
checked: false
},
{
id: 30,
label: 'Todos las Tareas',
value: costanti.ShowTypeTask.SHOW_ALL,
icon: 'check_circle',
checked: true
}
],
2019-03-13 01:53:53 +01:00
enUs: [
2019-03-04 17:28:29 +01:00
{
id: 10,
label: 'Show last N Completed',
value: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED,
icon: 'rowing',
checked: true
},
{
id: 20,
label: 'Task to complete',
value: costanti.ShowTypeTask.SHOW_ONLY_TOCOMPLETE,
icon: 'rowing',
checked: false
},
{
id: 30,
label: 'All Tasks',
value: costanti.ShowTypeTask.SHOW_ALL,
icon: 'check_circle',
checked: true
}
]
},
jsonCopy(src) {
return JSON.parse(JSON.stringify(src))
},
getItemLS(item) {
let ris = localStorage.getItem(item)
2019-03-13 01:53:53 +01:00
if ((ris == null) || (ris === '') || (ris === 'null')) {
ris = ''
2019-03-13 01:53:53 +01:00
}
return ris
},
notifyarraychanged(array) {
2019-03-13 01:53:53 +01:00
if (array.length > 0) {
array.splice(array.length - 1, 1, array[array.length - 1])
2019-03-13 01:53:53 +01:00
}
},
existArr(x) {
return x = (typeof x !== 'undefined' && x instanceof Array) ? x : []
},
json2array(json) {
2019-03-13 01:53:53 +01:00
const result = []
const keys = Object.keys(json)
keys.forEach((key) => {
result.push(json[key])
})
return result
},
showNotif(q: any, msg, data?: INotify | null) {
2019-03-13 13:40:17 +01:00
let myicon = data ? data.icon : 'ion-add'
if (!myicon) {
2019-03-13 13:40:17 +01:00
myicon = 'ion-add'
}
2019-03-13 13:40:17 +01:00
let mycolor = data ? data.color : 'primary'
if (!mycolor) {
2019-03-13 13:40:17 +01:00
mycolor = 'primary'
}
2019-03-13 13:40:17 +01:00
q.notify({
message: msg,
icon: myicon,
classes: 'my-notif-class',
color: mycolor,
timeout: 3000
})
},
checkLangPassed(mylang) {
const mybrowserLang = Quasar.lang.isoName
if (mylang !== '') {
if ((mylang.toLowerCase() === 'enus') || (mylang.toLowerCase() === 'en-us')) {
mylang = 'enUs'
}
if ((mylang.toLowerCase() === 'es') || (mylang.toLowerCase() === 'es-es') || (mylang.toLowerCase() === 'eses')) {
mylang = 'es'
}
2019-03-22 15:32:32 +01:00
if (!(tools.arrLangUsed.includes(mylang))) {
console.log('non incluso ', mylang)
mylang = tools.arrLangUsed[0]
// Metti Inglese come default
UserStore.mutations.setlang(mylang)
}
}
if (!mylang) {
mylang = process.env.LANG_DEFAULT
}
console.log('mylang calc : ', mylang)
return mylang
},
getimglogo() {
return 'statics/images/' + process.env.LOGO_REG
},
consolelogpao(strlog, strlog2 = '', strlog3 = '') {
globalroutines(null, 'log', strlog + ' ' + strlog2 + ' ' + strlog3, null)
},
2019-03-22 15:32:32 +01:00
aspettansec(numsec) {
return new Promise((resolve, reject) => {
2019-03-22 15:32:32 +01:00
setTimeout(() => {
resolve('anything')
}, numsec)
})
},
2019-03-22 18:49:38 +01:00
dragula_option($service, dragname) {
$service.options(dragname,
{
moves(el, source, handle, sibling) {
return !el.classList.contains('donotdrag') // elements are always draggable by default
},
accepts(el, target, source, sibling) {
return true // elements can be dropped in any of the `containers` by default
},
invalid(el, handle) {
return el.classList.contains('donotdrag') // don't prevent any drags from initiating by default
},
direction: 'vertical'
})
},
isLoggedToSystem() {
const tok = tools.getItemLS(tools.localStorage.token)
return !!tok
}
2019-03-22 18:49:38 +01:00
// _.cloneDeep( Per clonare un oggetto
}