forked from projects/fipamo
changed Fipamo API methods to be based on tasks, not api call type
This commit is contained in:
parent
a92f624b75
commit
75b4cb9ac2
6 changed files with 172 additions and 103 deletions
|
@ -179,7 +179,7 @@ router.post('/add-feature-background', background_upload, (req, res) => {
|
||||||
.then(settings => {
|
.then(settings => {
|
||||||
var path = req.files[0].path;
|
var path = req.files[0].path;
|
||||||
var image = path.substr(7, path.length);
|
var image = path.substr(7, path.length);
|
||||||
settings.background = '/' + image;
|
settings.global.background = '/' + image;
|
||||||
fs.writeJson('site/settings.json', settings);
|
fs.writeJson('site/settings.json', settings);
|
||||||
res.json({
|
res.json({
|
||||||
type: DataEvent.SITE_BACKGROUND_UPLOADED,
|
type: DataEvent.SITE_BACKGROUND_UPLOADED,
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
import FipamoApi, {
|
import FipamoApi from '../libraries/FipamoAPI';
|
||||||
REQUEST_TYPE_POST,
|
|
||||||
CONTENT_TYPE_JSON,
|
|
||||||
API_LOGIN,
|
|
||||||
API_INIT
|
|
||||||
} from '../libraries/FipamoAPI';
|
|
||||||
import DataUitls from './utils/DataUtils';
|
import DataUitls from './utils/DataUtils';
|
||||||
import * as DataEvent from './events/DataEvent';
|
import * as DataEvent from './events/DataEvent';
|
||||||
import DashManager from './controllers/DashManager';
|
import DashManager from './controllers/DashManager';
|
||||||
|
@ -46,13 +41,7 @@ export default class Base {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let authForm = data.formDataToJSON(document.getElementById('login'));
|
let authForm = data.formDataToJSON(document.getElementById('login'));
|
||||||
api.request(
|
api.login(authForm)
|
||||||
API_LOGIN,
|
|
||||||
DataEvent.AUTH_STATUS,
|
|
||||||
REQUEST_TYPE_POST,
|
|
||||||
CONTENT_TYPE_JSON,
|
|
||||||
authForm
|
|
||||||
)
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.type === DataEvent.REQUEST_LAME) {
|
if (response.type === DataEvent.REQUEST_LAME) {
|
||||||
notify.alert(response.message, false);
|
notify.alert(response.message, false);
|
||||||
|
@ -72,7 +61,7 @@ export default class Base {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let setUpForm = data.formDataToJSON(document.getElementById('init-form'));
|
let setUpForm = data.formDataToJSON(document.getElementById('init-form'));
|
||||||
api.request(API_INIT, DataEvent.API_INIT, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, setUpForm)
|
api.init(setUpForm)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.type === DataEvent.API_INIT_LAME) {
|
if (response.type === DataEvent.API_INIT_LAME) {
|
||||||
notify.alert(response.message, false);
|
notify.alert(response.message, false);
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
import FipamoAPI, {
|
import FipamoAPI from '../../libraries/FipamoAPI';
|
||||||
REQUEST_TYPE_POST,
|
|
||||||
CONTENT_TYPE_JSON,
|
|
||||||
API_NAV_SYNC
|
|
||||||
} from '../../libraries/FipamoAPI';
|
|
||||||
import NavActions from '../actions/NavActions';
|
import NavActions from '../actions/NavActions';
|
||||||
import * as DataEvent from '../events/DataEvent';
|
import * as DataEvent from '../events/DataEvent';
|
||||||
import Notifications from '../ui/Notifications';
|
import Notifications from '../ui/Notifications';
|
||||||
|
@ -22,13 +18,7 @@ export default class NavIndex {
|
||||||
Sortable.create(document.getElementById('nav-pages'), {
|
Sortable.create(document.getElementById('nav-pages'), {
|
||||||
onUpdate: () => {
|
onUpdate: () => {
|
||||||
new NavActions().syncMenu().then(data => {
|
new NavActions().syncMenu().then(data => {
|
||||||
api.request(
|
api.syncNav(data).then(r => {
|
||||||
API_NAV_SYNC,
|
|
||||||
DataEvent.API_SETTINGS_WRITE,
|
|
||||||
REQUEST_TYPE_POST,
|
|
||||||
CONTENT_TYPE_JSON,
|
|
||||||
data
|
|
||||||
).then(r => {
|
|
||||||
if (r.type == DataEvent.MENU_UPDATED) {
|
if (r.type == DataEvent.MENU_UPDATED) {
|
||||||
notify.alert(r.message, true);
|
notify.alert(r.message, true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -53,13 +43,7 @@ export default class NavIndex {
|
||||||
id = e.target.getAttribute('data-id');
|
id = e.target.getAttribute('data-id');
|
||||||
new NavActions().removeItem(id);
|
new NavActions().removeItem(id);
|
||||||
new NavActions().syncMenu().then(data => {
|
new NavActions().syncMenu().then(data => {
|
||||||
api.request(
|
api.syncNav(data).then(r => {
|
||||||
API_NAV_SYNC,
|
|
||||||
DataEvent.API_SETTINGS_WRITE,
|
|
||||||
REQUEST_TYPE_POST,
|
|
||||||
CONTENT_TYPE_JSON,
|
|
||||||
data
|
|
||||||
).then(r => {
|
|
||||||
if (r.type == DataEvent.MENU_UPDATED) {
|
if (r.type == DataEvent.MENU_UPDATED) {
|
||||||
notify.alert(r.message, true);
|
notify.alert(r.message, true);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
//TOOLS
|
//TOOLS
|
||||||
import FipamoAPI, {
|
import FipamoAPI, { API_NEW_PAGE, API_EDIT_PAGE } from '../../libraries/FipamoAPI';
|
||||||
REQUEST_TYPE_POST,
|
|
||||||
CONTENT_TYPE_FORM,
|
|
||||||
CONTENT_TYPE_JSON,
|
|
||||||
API_NEW_PAGE,
|
|
||||||
API_EDIT_PAGE,
|
|
||||||
API_DELETE_PAGE,
|
|
||||||
API_IMAGE_UPLOAD
|
|
||||||
} from '../../libraries/FipamoAPI';
|
|
||||||
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';
|
||||||
|
@ -137,15 +129,8 @@ export default class PostEditor {
|
||||||
e === EditorEvent.EDITOR_SAVE ? (apiUrl = API_NEW_PAGE) : (apiUrl = API_EDIT_PAGE);
|
e === EditorEvent.EDITOR_SAVE ? (apiUrl = API_NEW_PAGE) : (apiUrl = API_EDIT_PAGE);
|
||||||
new PageActions()
|
new PageActions()
|
||||||
.collectInfo(document.getElementById('featured-image-upload').files[0])
|
.collectInfo(document.getElementById('featured-image-upload').files[0])
|
||||||
|
|
||||||
.then(page => {
|
.then(page => {
|
||||||
api.request(
|
api.pageEdit(apiUrl, page)
|
||||||
apiUrl,
|
|
||||||
DataEvent.API_PAGE_WRITE,
|
|
||||||
REQUEST_TYPE_POST,
|
|
||||||
CONTENT_TYPE_FORM,
|
|
||||||
page
|
|
||||||
)
|
|
||||||
.then(r => {
|
.then(r => {
|
||||||
if (
|
if (
|
||||||
r.type === DataEvent.PAGE_ERROR ||
|
r.type === DataEvent.PAGE_ERROR ||
|
||||||
|
@ -173,13 +158,7 @@ export default class PostEditor {
|
||||||
}
|
}
|
||||||
if (confirm("AYE! You know you're deleting this post, right?")) {
|
if (confirm("AYE! You know you're deleting this post, right?")) {
|
||||||
let id = { id: this.postUUID };
|
let id = { id: this.postUUID };
|
||||||
api.request(
|
api.pageDelete(id)
|
||||||
API_DELETE_PAGE,
|
|
||||||
DataEvent.API_PAGE_DELETE,
|
|
||||||
REQUEST_TYPE_POST,
|
|
||||||
CONTENT_TYPE_JSON,
|
|
||||||
id
|
|
||||||
)
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
window.location = '/@/dashboard/page/list/';
|
window.location = '/@/dashboard/page/list/';
|
||||||
})
|
})
|
||||||
|
@ -238,8 +217,6 @@ export default class PostEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleImageUpload(type, files) {
|
handleImageUpload(type, files) {
|
||||||
let url = API_IMAGE_UPLOAD;
|
|
||||||
let eventType = DataEvent.API_IMAGES_UPLOAD;
|
|
||||||
let self = this;
|
let self = this;
|
||||||
var imageData = new FormData();
|
var imageData = new FormData();
|
||||||
for (var i = 0; i < files.length; i++) {
|
for (var i = 0; i < files.length; i++) {
|
||||||
|
@ -250,7 +227,7 @@ export default class PostEditor {
|
||||||
}
|
}
|
||||||
imageData.append('post_image', file, file.name);
|
imageData.append('post_image', file, file.name);
|
||||||
}
|
}
|
||||||
api.request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData)
|
api.pageImageUpload(imageData)
|
||||||
.then(r => {
|
.then(r => {
|
||||||
if (r.type == DataEvent.POST_IMAGE_ADDED)
|
if (r.type == DataEvent.POST_IMAGE_ADDED)
|
||||||
self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url);
|
self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url);
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
import SettingsActions from '../actions/SettingsActions';
|
import SettingsActions from '../actions/SettingsActions';
|
||||||
import FipamoAPI, {
|
import FipamoAPI from '../../libraries/FipamoAPI';
|
||||||
REQUEST_TYPE_POST,
|
|
||||||
CONTENT_TYPE_FORM,
|
|
||||||
CONTENT_TYPE_JSON,
|
|
||||||
API_SETTINGS_SYNC,
|
|
||||||
API_UPLOAD_AVATAR,
|
|
||||||
API_UPLOAD_BACKGROUND,
|
|
||||||
API_PUBLISH_PAGES
|
|
||||||
} from '../../libraries/FipamoAPI';
|
|
||||||
import * as DataEvent from '../../../src/com/events/DataEvent';
|
import * as DataEvent from '../../../src/com/events/DataEvent';
|
||||||
import Mailer from '../actions/Mailer';
|
import Mailer from '../actions/Mailer';
|
||||||
import Notifications from '../ui/Notifications';
|
import Notifications from '../ui/Notifications';
|
||||||
|
@ -31,13 +23,7 @@ export default class SettingsIndex {
|
||||||
new SettingsActions()
|
new SettingsActions()
|
||||||
.getInfo()
|
.getInfo()
|
||||||
.then(data => {
|
.then(data => {
|
||||||
api.request(
|
api.syncSettings(data).then(r => {
|
||||||
API_SETTINGS_SYNC,
|
|
||||||
DataEvent.API_SETTINGS_WRITE,
|
|
||||||
REQUEST_TYPE_POST,
|
|
||||||
CONTENT_TYPE_JSON,
|
|
||||||
data
|
|
||||||
).then(r => {
|
|
||||||
if (r.type == DataEvent.SETTINGS_UPDATED) {
|
if (r.type == DataEvent.SETTINGS_UPDATED) {
|
||||||
notify.alert(r.message, true);
|
notify.alert(r.message, true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -155,21 +141,7 @@ export default class SettingsIndex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleImageUpload(type, files) {
|
handleImageUpload(type, files) {
|
||||||
let url = '';
|
api.settingsImageUpload(type, files)
|
||||||
let eventType = DataEvent.API_IMAGES_UPLOAD;
|
|
||||||
type == 'avatar-upload' ? (url = API_UPLOAD_AVATAR) : (url = API_UPLOAD_BACKGROUND);
|
|
||||||
var imageData = new FormData();
|
|
||||||
for (var i = 0; i < files.length; i++) {
|
|
||||||
var file = files[i];
|
|
||||||
// Check the file type.
|
|
||||||
if (!file.type.match('image.*')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
type == 'avatar-upload'
|
|
||||||
? imageData.append('avatar_upload', file, file.name)
|
|
||||||
: imageData.append('background_upload', file, file.name);
|
|
||||||
}
|
|
||||||
api.request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData)
|
|
||||||
.then(r => {
|
.then(r => {
|
||||||
if (r.type == DataEvent.AVATAR_UPLOADED) {
|
if (r.type == DataEvent.AVATAR_UPLOADED) {
|
||||||
notify.alert(r.message, true);
|
notify.alert(r.message, true);
|
||||||
|
@ -187,13 +159,7 @@ export default class SettingsIndex {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
let task = { task: 'publish all pages' };
|
let task = { task: 'publish all pages' };
|
||||||
api.request(
|
api.publishSite(task)
|
||||||
API_PUBLISH_PAGES,
|
|
||||||
DataEvent.API_RENDER_PAGES,
|
|
||||||
REQUEST_TYPE_POST,
|
|
||||||
CONTENT_TYPE_JSON,
|
|
||||||
task
|
|
||||||
)
|
|
||||||
.then(r => {
|
.then(r => {
|
||||||
notify.alert(r.message, true);
|
notify.alert(r.message, true);
|
||||||
})
|
})
|
||||||
|
|
|
@ -27,7 +27,7 @@ export default class APIUtils {
|
||||||
this.token = null;
|
this.token = null;
|
||||||
//checks backend to see if user is logged in
|
//checks backend to see if user is logged in
|
||||||
//and requests encrypted token for api calls
|
//and requests encrypted token for api calls
|
||||||
this.request(API_STATUS).then(response => {
|
this._request(API_STATUS).then(response => {
|
||||||
if (response.type === DataEvent.API_REQUEST_GOOD) {
|
if (response.type === DataEvent.API_REQUEST_GOOD) {
|
||||||
this.token = response.token;
|
this.token = response.token;
|
||||||
} else {
|
} else {
|
||||||
|
@ -36,10 +36,163 @@ export default class APIUtils {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// methods
|
// public
|
||||||
//--------------------------
|
//--------------------------
|
||||||
//TODO: Make 'private' class
|
login(data) {
|
||||||
request(
|
return new Promise((resolve, reject) => {
|
||||||
|
this._request(
|
||||||
|
API_LOGIN,
|
||||||
|
DataEvent.AUTH_STATUS,
|
||||||
|
REQUEST_TYPE_POST,
|
||||||
|
CONTENT_TYPE_JSON,
|
||||||
|
data
|
||||||
|
)
|
||||||
|
.then(result => {
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
init(data) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this._request(API_INIT, DataEvent.API_INIT, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data)
|
||||||
|
.then(result => {
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
syncSettings(data) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this._request(
|
||||||
|
API_SETTINGS_SYNC,
|
||||||
|
DataEvent.API_SETTINGS_WRITE,
|
||||||
|
REQUEST_TYPE_POST,
|
||||||
|
CONTENT_TYPE_JSON,
|
||||||
|
data
|
||||||
|
)
|
||||||
|
.then(result => {
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
settingsImageUpload(type, files) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let url = '';
|
||||||
|
let eventType = DataEvent.API_IMAGES_UPLOAD;
|
||||||
|
type == 'avatar-upload' ? (url = API_UPLOAD_AVATAR) : (url = API_UPLOAD_BACKGROUND);
|
||||||
|
var imageData = new FormData();
|
||||||
|
for (var i = 0; i < files.length; i++) {
|
||||||
|
var file = files[i];
|
||||||
|
// Check the file type.
|
||||||
|
if (!file.type.match('image.*')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
type == 'avatar-upload'
|
||||||
|
? imageData.append('avatar_upload', file, file.name)
|
||||||
|
: imageData.append('background_upload', file, file.name);
|
||||||
|
}
|
||||||
|
this._request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData)
|
||||||
|
.then(r => {
|
||||||
|
resolve(r);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
publishSite(data) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this._request(
|
||||||
|
API_PUBLISH_PAGES,
|
||||||
|
DataEvent.API_RENDER_PAGES,
|
||||||
|
REQUEST_TYPE_POST,
|
||||||
|
CONTENT_TYPE_JSON,
|
||||||
|
data
|
||||||
|
)
|
||||||
|
.then(result => {
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pageEdit(url, data) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this._request(url, DataEvent.API_PAGE_WRITE, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, data)
|
||||||
|
.then(result => {
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
pageDelete(data) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this._request(
|
||||||
|
API_DELETE_PAGE,
|
||||||
|
DataEvent.API_PAGE_DELETE,
|
||||||
|
REQUEST_TYPE_POST,
|
||||||
|
CONTENT_TYPE_JSON,
|
||||||
|
data
|
||||||
|
)
|
||||||
|
.then(result => {
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
pageImageUpload(file) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this._request(
|
||||||
|
API_IMAGE_UPLOAD,
|
||||||
|
DataEvent.API_IMAGES_UPLOAD,
|
||||||
|
REQUEST_TYPE_POST,
|
||||||
|
CONTENT_TYPE_FORM,
|
||||||
|
file
|
||||||
|
)
|
||||||
|
.then(result => {
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
syncNav(data) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this._request(
|
||||||
|
API_NAV_SYNC,
|
||||||
|
DataEvent.API_SETTINGS_WRITE,
|
||||||
|
REQUEST_TYPE_POST,
|
||||||
|
CONTENT_TYPE_JSON,
|
||||||
|
data
|
||||||
|
)
|
||||||
|
.then(result => {
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//--------------------------
|
||||||
|
// private
|
||||||
|
//--------------------------
|
||||||
|
_request(
|
||||||
requestURL,
|
requestURL,
|
||||||
eventType,
|
eventType,
|
||||||
requestType = REQUEST_TYPE_GET,
|
requestType = REQUEST_TYPE_GET,
|
||||||
|
|
Loading…
Reference in a new issue