consolidated fipamo api admin methods
This commit is contained in:
parent
0fa1bebc8a
commit
957a389b8b
4 changed files with 68 additions and 60 deletions
|
@ -191,9 +191,11 @@ export default class Book {
|
||||||
this.getPage(id)
|
this.getPage(id)
|
||||||
.then(page => {
|
.then(page => {
|
||||||
let body = _.mapValues(page.metadata);
|
let body = _.mapValues(page.metadata);
|
||||||
|
|
||||||
body.content = page.content;
|
body.content = page.content;
|
||||||
body.deleted = moment(Date.now()).format();
|
body.deleted = moment(Date.now()).format();
|
||||||
body.menu = false;
|
body.menu = false;
|
||||||
|
|
||||||
self.editPage(body, body.uuid, DataEvent.API_PAGE_WRITE, user)
|
self.editPage(body, body.uuid, DataEvent.API_PAGE_WRITE, user)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
let item = {
|
let item = {
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
//TOOLS
|
//TOOLS
|
||||||
import FipamoAPI, { API_NEW_PAGE, API_EDIT_PAGE } from '../../libraries/FipamoAPI';
|
import FipamoAPI, {
|
||||||
|
TASK_PAGE_CREATE,
|
||||||
|
TASK_PAGE_EDIT,
|
||||||
|
TASK_PAGE_DELETE
|
||||||
|
} 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';
|
||||||
|
@ -125,12 +129,12 @@ export default class PostEditor {
|
||||||
switch (e) {
|
switch (e) {
|
||||||
case EditorEvent.EDITOR_SAVE:
|
case EditorEvent.EDITOR_SAVE:
|
||||||
case EditorEvent.EDITOR_UPDATE:
|
case EditorEvent.EDITOR_UPDATE:
|
||||||
var apiUrl = '';
|
var task = '';
|
||||||
e === EditorEvent.EDITOR_SAVE ? (apiUrl = API_NEW_PAGE) : (apiUrl = API_EDIT_PAGE);
|
e === EditorEvent.EDITOR_SAVE ? (task = TASK_PAGE_CREATE) : (task = TASK_PAGE_EDIT);
|
||||||
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.pageEdit(apiUrl, page)
|
api.pageActions(task, page)
|
||||||
.then(r => {
|
.then(r => {
|
||||||
if (
|
if (
|
||||||
r.type === DataEvent.PAGE_ERROR ||
|
r.type === DataEvent.PAGE_ERROR ||
|
||||||
|
@ -158,7 +162,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.pageDelete(id)
|
api.pageActions(TASK_PAGE_DELETE, id)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
window.location = '/@/dashboard/page/list/';
|
window.location = '/@/dashboard/page/list/';
|
||||||
})
|
})
|
||||||
|
@ -218,22 +222,13 @@ export default class PostEditor {
|
||||||
}
|
}
|
||||||
handleImageUpload(type, files) {
|
handleImageUpload(type, files) {
|
||||||
let self = this;
|
let self = this;
|
||||||
var imageData = new FormData();
|
api.imageUpload(type, files)
|
||||||
for (var i = 0; i < files.length; i++) {
|
|
||||||
var file = files[i];
|
|
||||||
// Check the file type.
|
|
||||||
if (!file.type.match('image.*')) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
imageData.append('post_image', file, file.name);
|
|
||||||
}
|
|
||||||
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);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
//console.log(err)
|
//console.log('ERROR', err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ export default class SettingsIndex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleImageUpload(type, files) {
|
handleImageUpload(type, files) {
|
||||||
api.settingsImageUpload(type, files)
|
api.imageUpload(type, files)
|
||||||
.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);
|
||||||
|
|
|
@ -2,6 +2,9 @@ export const REQUEST_TYPE_POST = 'POST';
|
||||||
export const REQUEST_TYPE_GET = 'GET';
|
export const REQUEST_TYPE_GET = 'GET';
|
||||||
export const REQUEST_TYPE_PUT = 'PUT';
|
export const REQUEST_TYPE_PUT = 'PUT';
|
||||||
export const REQUEST_TYPE_DELETE = 'DELETE';
|
export const REQUEST_TYPE_DELETE = 'DELETE';
|
||||||
|
export const TASK_PAGE_CREATE = 'createNewPage';
|
||||||
|
export const TASK_PAGE_EDIT = 'editPage';
|
||||||
|
export const TASK_PAGE_DELETE = 'deletePage';
|
||||||
export const CONTENT_TYPE_JSON = 'json';
|
export const CONTENT_TYPE_JSON = 'json';
|
||||||
export const CONTENT_TYPE_FORM = 'x-www-form-urlencoded';
|
export const CONTENT_TYPE_FORM = 'x-www-form-urlencoded';
|
||||||
export const API_STATUS = '/api/v1/auth/status';
|
export const API_STATUS = '/api/v1/auth/status';
|
||||||
|
@ -83,11 +86,20 @@ export default class APIUtils {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
settingsImageUpload(type, files) {
|
imageUpload(type, files) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let url = '';
|
let url = '';
|
||||||
let eventType = DataEvent.API_IMAGES_UPLOAD;
|
switch (type) {
|
||||||
type == 'avatar-upload' ? (url = API_UPLOAD_AVATAR) : (url = API_UPLOAD_BACKGROUND);
|
case 'avatar-upload':
|
||||||
|
url = API_UPLOAD_AVATAR;
|
||||||
|
break;
|
||||||
|
case 'background-upload':
|
||||||
|
url = API_UPLOAD_BACKGROUND;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
url = API_IMAGE_UPLOAD;
|
||||||
|
break;
|
||||||
|
}
|
||||||
var imageData = new FormData();
|
var imageData = new FormData();
|
||||||
for (var i = 0; i < files.length; i++) {
|
for (var i = 0; i < files.length; i++) {
|
||||||
var file = files[i];
|
var file = files[i];
|
||||||
|
@ -95,11 +107,21 @@ export default class APIUtils {
|
||||||
if (!file.type.match('image.*')) {
|
if (!file.type.match('image.*')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
type == 'avatar-upload'
|
if (type === 'avatar-upload') {
|
||||||
? imageData.append('avatar_upload', file, file.name)
|
imageData.append('avatar_upload', file, file.name);
|
||||||
: imageData.append('background_upload', file, file.name);
|
} else if (type === 'background-upload') {
|
||||||
|
imageData.append('background_upload', file, file.name);
|
||||||
|
} else {
|
||||||
|
imageData.append('post_image', file, file.name);
|
||||||
}
|
}
|
||||||
this._request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData)
|
}
|
||||||
|
this._request(
|
||||||
|
url,
|
||||||
|
DataEvent.API_IMAGES_UPLOAD,
|
||||||
|
REQUEST_TYPE_POST,
|
||||||
|
CONTENT_TYPE_FORM,
|
||||||
|
imageData
|
||||||
|
)
|
||||||
.then(r => {
|
.then(r => {
|
||||||
resolve(r);
|
resolve(r);
|
||||||
})
|
})
|
||||||
|
@ -126,43 +148,32 @@ export default class APIUtils {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pageEdit(url, data) {
|
pageActions(task, data) {
|
||||||
return new Promise((resolve, reject) => {
|
let url, event, content;
|
||||||
this._request(url, DataEvent.API_PAGE_WRITE, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, data)
|
switch (task) {
|
||||||
.then(result => {
|
case TASK_PAGE_CREATE:
|
||||||
resolve(result);
|
url = API_NEW_PAGE;
|
||||||
})
|
event = DataEvent.API_PAGE_WRITE;
|
||||||
.catch(err => {
|
content = CONTENT_TYPE_FORM;
|
||||||
reject(err);
|
break;
|
||||||
});
|
case TASK_PAGE_EDIT:
|
||||||
});
|
url = API_EDIT_PAGE;
|
||||||
|
event = DataEvent.API_PAGE_WRITE;
|
||||||
|
content = CONTENT_TYPE_FORM;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TASK_PAGE_DELETE:
|
||||||
|
url = API_DELETE_PAGE;
|
||||||
|
event = DataEvent.API_PAGE_DELETE;
|
||||||
|
content = CONTENT_TYPE_JSON;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
pageDelete(data) {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._request(
|
this._request(url, event, REQUEST_TYPE_POST, content, data)
|
||||||
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 => {
|
.then(result => {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue