removed uneccessary util files, moved token set up to API util constructor, notifications style tweak

pull/20/head
Ro 4 years ago
parent eeeb4f9af6
commit ca6e9e488b

@ -9,7 +9,6 @@ export default class NavIndex {
// constructor // constructor
//-------------------------- //--------------------------
constructor() { constructor() {
api.authStatus();
this.start(); this.start();
} }
//-------------------------- //--------------------------

@ -7,7 +7,7 @@ import ApiUtils, {
import * as DataEvent from '../events/DataEvent'; import * as DataEvent from '../events/DataEvent';
import PageActions from '../actions/PageActions'; import PageActions from '../actions/PageActions';
import * as EditorEvent from '../events/EditorEvent'; import * as EditorEvent from '../events/EditorEvent';
import TinyDatePicker from 'tiny-date-picker'; //import TinyDatePicker from 'tiny-date-picker';
import TextEditor from '../ui/TextEditor'; import TextEditor from '../ui/TextEditor';
import Notfications from '../ui/Notifications'; import Notfications from '../ui/Notifications';
const api = new ApiUtils(); const api = new ApiUtils();

@ -15,7 +15,6 @@ export default class SettingsIndex {
// constructor // constructor
//-------------------------- //--------------------------
constructor() { constructor() {
api.authStatus();
this.start(); this.start();
} }
//-------------------------- //--------------------------

@ -12,11 +12,6 @@ export default class APIUtils {
constructor() { constructor() {
this.percentComplete = 0; this.percentComplete = 0;
this.token = null; this.token = null;
}
//--------------------------
// methods
//--------------------------
authStatus() {
this.request('/api/v1/auth/status').then(r => { this.request('/api/v1/auth/status').then(r => {
let response = JSON.parse(r.request['response']); let response = JSON.parse(r.request['response']);
if (response.type === DataEvent.API_REQUEST_GOOD) { if (response.type === DataEvent.API_REQUEST_GOOD) {
@ -26,6 +21,9 @@ export default class APIUtils {
} }
}); });
} }
//--------------------------
// methods
//--------------------------
request( request(
requestURL, requestURL,
eventType, eventType,

@ -1,178 +0,0 @@
'use strict';
import DataUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from './DataUtils';
import Dexie from 'dexie';
import * as DataEvent from '../events/DataEvent';
export var COUNT;
export var FINAL_KEY;
export default class DBUtils {
//--------------------------
// constructor
//--------------------------
constructor() {
/**
* NOTE: DB ERRORS REPLICATE.
* WHEN FIXING A BUG, FIX DATA WITH JSON BACKUP
*/
this.dataUtils = new DataUtils();
this.db = new Dexie('fipamo_posts');
this.db.version(1).stores({
postList: 'id,post'
});
this.db.postList.toArray(array => {
COUNT = array.length;
FINAL_KEY = 0;
if (COUNT != 0) FINAL_KEY = array[COUNT - 1].id;
});
}
//--------------------------
// methods
//--------------------------
modify(id, postData) {
let self = this;
let freshID;
return new Promise(function(resolve, reject) {
if (id == null) {
self.db.postList
.put(postData)
.then(fresh => {
freshID = fresh;
})
.catch(e => {
let err = {
message: 'PUT ERROR',
error: e
};
return err;
});
} else {
//console.log("UPDATED", postData);
self.db.postList
.update(Number(id), {
post: postData
})
.then(() => {})
.catch(e => {
let err = {
message: 'UPDATE ERROR',
error: e
};
return err;
});
}
self.db.postList.toArray(array => {
self.syncRemote(array, freshID)
.then(response => {
resolve({
response
});
})
.catch(err => {
reject({
err
});
});
});
});
}
syncLocal(array) {
let self = this;
return new Promise(function(resolve, reject) {
self.db.postList.clear().then(() => {
self.db.postList
.bulkAdd(array)
.then(() => {
self.db.postList.toArray(() => {
let event = DataEvent.LOCAL_DB_READY;
resolve({
event
});
});
})
.catch(Dexie.BulkError, e => {
reject({
e
});
});
});
});
}
syncRemote(db, newPostId) {
let self = this;
return new Promise(function(resolve, reject) {
self.dataUtils
.request(
'/api/post/sync',
DataEvent.POSTS_SYNCED,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
db
)
.then(response => {
let bounce = {
message: response,
newPost: newPostId
};
resolve(bounce);
})
.catch(err => {
reject(err);
});
});
}
getPost(id) {
let self = this;
if (id == null) {
return new Promise(function(resolve, reject) {
self.db.postList
.toArray(array => {
resolve(array);
})
.catch(err => {
reject(err);
});
});
} else {
return new Promise(function(resolve, reject) {
self.db.postList
.get(Number(id))
.then(obj => {
resolve(obj);
})
.catch(err => {
reject(err);
});
});
}
}
archivePost(id, archive) {
let self = this;
return new Promise(function(resolve, reject) {
self.db.postList
.update(Number(id), {
post: archive
})
.then(() => {
self.db.postList.toArray(array => {
self.syncRemote(array, null)
.then(response => {
resolve({
response
});
})
.catch(err => {
reject({
err
});
});
});
})
.catch(() => {
//console.log('ERROR', e);
});
});
}
//--------------------------
// event handlers
//--------------------------
}

@ -1,137 +0,0 @@
export const roles = {
hnic: {
client_admin: {
create: true,
read: true,
update: true,
delete: true
},
client_user: {
create: true,
read: true,
update: true,
delete: true
},
client_project: {
create: true,
read: true,
update: true,
delete: true
},
folio_project: {
create: true,
read: true,
update: true,
delete: true
},
bookmark: {
create: true,
read: true,
update: true,
delete: true
},
post: {
create: true,
read: true,
update: true,
delete: true
},
settings: {
create: true,
read: true,
update: true,
delete: true
}
},
client: {
client_admin: {
create: false,
read: true,
update: false,
delete: false
},
client_user: {
create: true,
read: true,
update: true,
delete: true
},
client_project: {
create: true,
read: true,
update: true,
delete: false
},
folio_project: {
create: false,
read: false,
update: false,
delete: false
}
},
user: {
client_admin: {
create: false,
read: false,
update: false,
delete: false
},
client_user: {
create: false,
read: true,
update: false,
delete: false
},
client_project: {
create: false,
read: true,
update: true,
delete: false
},
folio_project: {
create: false,
read: false,
update: false,
delete: false
},
bookmark: {
create: true,
read: true,
update: true,
delete: true
},
post: {
create: false,
read: false,
update: false,
delete: false
}
}
};
export const TASK_CREATE = 'create';
export const TASK_UPDATE = 'update';
export const TASK_READ = 'read';
export const TASK_DELETE = 'delete';
export const OBJECT_CLIENT_ADMIN = 'client_admin';
export const OBJECT_CLIENT_USER = 'client_user';
export const OBJECT_PROJECT_CLIENT = 'client_project';
export const OBJECT_PROJECT_FOLIO = 'folio_project';
export const OBJECT_BOOKMARK = 'bookmark';
export const OBJECT_POST = 'post';
export const OBJECT_SETTINGS = 'settings';
export default class RightsManager {
//--------------------------
// constructor
//--------------------------
constructor() {}
//--------------------------
// methods
//--------------------------
check(role, object, task) {
//console.log(role + " *** " + object + " *** " + task);
return roles[role][object][task];
}
//--------------------------
// event handlers
//--------------------------
}

@ -21,7 +21,7 @@ svg.icons
z-index 2000 z-index 2000
height 10% height 10%
width 100% width 100%
display block display none
align-items center align-items center
justify-content center justify-content center
padding 0 padding 0

Loading…
Cancel
Save