created Fipamo API Library, moved all API urls to API class
This commit is contained in:
parent
ca6e9e488b
commit
36d6631df9
8 changed files with 78 additions and 33 deletions
|
@ -1,10 +1,10 @@
|
||||||
import ApiUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from './utils/APIUtils';
|
import FipamoApi, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON, API_LOGIN } 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';
|
||||||
import Notfications from './ui/Notifications';
|
import Notfications from './ui/Notifications';
|
||||||
|
|
||||||
const api = new ApiUtils();
|
const api = new FipamoApi();
|
||||||
const data = new DataUitls();
|
const data = new DataUitls();
|
||||||
const notify = new Notfications();
|
const notify = new Notfications();
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ export default class Base {
|
||||||
.getElementById('login-btn')
|
.getElementById('login-btn')
|
||||||
.addEventListener('click', e => this.handleLogin(e));
|
.addEventListener('click', e => this.handleLogin(e));
|
||||||
} else {
|
} else {
|
||||||
let manager = new DashManager();
|
new DashManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//--------------------------
|
//--------------------------
|
||||||
|
@ -36,7 +36,7 @@ export default class Base {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let authForm = data.formDataToJSON(document.getElementById('login'));
|
let authForm = data.formDataToJSON(document.getElementById('login'));
|
||||||
api.request(
|
api.request(
|
||||||
'/api/v1/auth/login',
|
API_LOGIN,
|
||||||
DataEvent.AUTH_STATUS,
|
DataEvent.AUTH_STATUS,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
|
|
|
@ -22,6 +22,11 @@ export default class NavActions {
|
||||||
resolve(navData);
|
resolve(navData);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeItem(id) {
|
||||||
|
document.getElementById('nav-pages').removeChild(document.getElementById(id));
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// event handlers
|
// event handlers
|
||||||
//--------------------------
|
//--------------------------
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
import ApiUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../utils/APIUtils';
|
import FipamoAPI, {
|
||||||
|
REQUEST_TYPE_POST,
|
||||||
|
CONTENT_TYPE_JSON,
|
||||||
|
API_GET_NAV,
|
||||||
|
API_NAV_SYNC
|
||||||
|
} from '../../libraries/FipamoAPI';
|
||||||
import StringUtils from '../utils/StringUtils';
|
import StringUtils from '../utils/StringUtils';
|
||||||
import * as DataEvent from '../events/DataEvent';
|
import * as DataEvent from '../events/DataEvent';
|
||||||
const api = new ApiUtils();
|
const api = new FipamoAPI();
|
||||||
export default class PostActions {
|
export default class PostActions {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// constructor
|
// constructor
|
||||||
|
@ -72,7 +77,7 @@ export default class PostActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateNav(add, id, post) {
|
updateNav(add, id, post) {
|
||||||
api.request('/api/settings/nav', DataEvent.SETTINGS_LOADED)
|
api.request(API_GET_NAV, DataEvent.SETTINGS_LOADED)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
let menu = JSON.parse(response.request['response']);
|
let menu = JSON.parse(response.request['response']);
|
||||||
let item = {
|
let item = {
|
||||||
|
@ -91,7 +96,7 @@ export default class PostActions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
api.request(
|
api.request(
|
||||||
'/api/settings/nav-sync',
|
API_NAV_SYNC,
|
||||||
DataEvent.API_SETTINGS_WRITE,
|
DataEvent.API_SETTINGS_WRITE,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
import ApiUtils, { REQUEST_TYPE_POST, CONTENT_TYPE_JSON } from '../../../src/com/utils/APIUtils';
|
import 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';
|
||||||
const notify = new Notifications();
|
const notify = new Notifications();
|
||||||
const api = new ApiUtils();
|
const api = new FipamoAPI();
|
||||||
export default class NavIndex {
|
export default class NavIndex {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// constructor
|
// constructor
|
||||||
|
@ -19,7 +23,7 @@ export default class NavIndex {
|
||||||
onUpdate: () => {
|
onUpdate: () => {
|
||||||
new NavActions().syncMenu().then(data => {
|
new NavActions().syncMenu().then(data => {
|
||||||
api.request(
|
api.request(
|
||||||
'/api/v1/settings/nav-sync',
|
API_NAV_SYNC,
|
||||||
DataEvent.API_SETTINGS_WRITE,
|
DataEvent.API_SETTINGS_WRITE,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
|
@ -49,6 +53,22 @@ export default class NavIndex {
|
||||||
case 'remove-item':
|
case 'remove-item':
|
||||||
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 => {
|
||||||
|
api.request(
|
||||||
|
API_NAV_SYNC,
|
||||||
|
DataEvent.API_SETTINGS_WRITE,
|
||||||
|
REQUEST_TYPE_POST,
|
||||||
|
CONTENT_TYPE_JSON,
|
||||||
|
data
|
||||||
|
).then(response => {
|
||||||
|
let r = JSON.parse(response.request['response']);
|
||||||
|
if (r.type == DataEvent.MENU_UPDATED) {
|
||||||
|
notify.alert(r.message, true);
|
||||||
|
} else {
|
||||||
|
notify.alert(r.message, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case 'edit-item':
|
case 'edit-item':
|
||||||
window.location = '/@/dashboard/pages/edit/' + e.target.getAttribute('data-id');
|
window.location = '/@/dashboard/pages/edit/' + e.target.getAttribute('data-id');
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
//TOOLS
|
//TOOLS
|
||||||
import ApiUtils, {
|
import FipamoAPI, {
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_FORM,
|
CONTENT_TYPE_FORM,
|
||||||
CONTENT_TYPE_JSON
|
CONTENT_TYPE_JSON,
|
||||||
} from '../utils/APIUtils';
|
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';
|
||||||
//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 FipamoAPI();
|
||||||
const notify = new Notfications();
|
const notify = new Notfications();
|
||||||
export default class PostEditor {
|
export default class PostEditor {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
|
@ -23,7 +27,6 @@ export default class PostEditor {
|
||||||
this.postID = null;
|
this.postID = null;
|
||||||
this.postUUID = null;
|
this.postUUID = null;
|
||||||
this.postLayout = null;
|
this.postLayout = null;
|
||||||
api.authStatus();
|
|
||||||
if (document.getElementById('post-edit-index').getAttribute('data-index')) {
|
if (document.getElementById('post-edit-index').getAttribute('data-index')) {
|
||||||
this.postID = document.getElementById('post-edit-index').getAttribute('data-index');
|
this.postID = document.getElementById('post-edit-index').getAttribute('data-index');
|
||||||
this.postUUID = document.getElementById('post-edit-index').getAttribute('data-uuid');
|
this.postUUID = document.getElementById('post-edit-index').getAttribute('data-uuid');
|
||||||
|
@ -131,9 +134,7 @@ export default class PostEditor {
|
||||||
case EditorEvent.EDITOR_SAVE:
|
case EditorEvent.EDITOR_SAVE:
|
||||||
case EditorEvent.EDITOR_UPDATE:
|
case EditorEvent.EDITOR_UPDATE:
|
||||||
var apiUrl = '';
|
var apiUrl = '';
|
||||||
e === EditorEvent.EDITOR_SAVE
|
e === EditorEvent.EDITOR_SAVE ? (apiUrl = API_NEW_PAGE) : (apiUrl = API_EDIT_PAGE);
|
||||||
? (apiUrl = '/api/v1/page/write/new')
|
|
||||||
: (apiUrl = '/api/v1/page/write');
|
|
||||||
new PageActions()
|
new PageActions()
|
||||||
.collectInfo(document.getElementById('featured-image-upload').files[0])
|
.collectInfo(document.getElementById('featured-image-upload').files[0])
|
||||||
|
|
||||||
|
@ -174,7 +175,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.request(
|
||||||
'/api/v1/page/delete',
|
API_DELETE_PAGE,
|
||||||
DataEvent.API_PAGE_DELETE,
|
DataEvent.API_PAGE_DELETE,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
|
@ -238,7 +239,7 @@ export default class PostEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleImageUpload(type, files) {
|
handleImageUpload(type, files) {
|
||||||
let url = '/api/v1/page/add-post-image';
|
let url = API_IMAGE_UPLOAD;
|
||||||
let eventType = DataEvent.API_IMAGES_UPLOAD;
|
let eventType = DataEvent.API_IMAGES_UPLOAD;
|
||||||
let self = this;
|
let self = this;
|
||||||
var imageData = new FormData();
|
var imageData = new FormData();
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
import SettingsActions from '../actions/SettingsActions';
|
import SettingsActions from '../actions/SettingsActions';
|
||||||
import ApiUtils, {
|
import FipamoAPI, {
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_FORM,
|
CONTENT_TYPE_FORM,
|
||||||
CONTENT_TYPE_JSON
|
CONTENT_TYPE_JSON,
|
||||||
} from '../../../src/com/utils/APIUtils';
|
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';
|
||||||
const api = new ApiUtils();
|
const api = new FipamoAPI();
|
||||||
const notify = new Notifications();
|
const notify = new Notifications();
|
||||||
const mailer = new Mailer();
|
const mailer = new Mailer();
|
||||||
export default class SettingsIndex {
|
export default class SettingsIndex {
|
||||||
|
@ -28,7 +32,7 @@ export default class SettingsIndex {
|
||||||
.getInfo()
|
.getInfo()
|
||||||
.then(data => {
|
.then(data => {
|
||||||
api.request(
|
api.request(
|
||||||
'/api/v1/settings/sync',
|
API_SETTINGS_SYNC,
|
||||||
DataEvent.API_SETTINGS_WRITE,
|
DataEvent.API_SETTINGS_WRITE,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
|
@ -154,9 +158,7 @@ export default class SettingsIndex {
|
||||||
handleImageUpload(type, files) {
|
handleImageUpload(type, files) {
|
||||||
let url = '';
|
let url = '';
|
||||||
let eventType = DataEvent.API_IMAGES_UPLOAD;
|
let eventType = DataEvent.API_IMAGES_UPLOAD;
|
||||||
type == 'avatar-upload'
|
type == 'avatar-upload' ? (url = API_UPLOAD_AVATAR) : (url = API_UPLOAD_BACKGROUND);
|
||||||
? (url = '/api/v1/settings/add-avatar')
|
|
||||||
: (url = '/api/v1/settings/add-feature-background');
|
|
||||||
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];
|
||||||
|
@ -189,7 +191,7 @@ export default class SettingsIndex {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
let task = { task: 'publish all pages' };
|
let task = { task: 'publish all pages' };
|
||||||
api.request(
|
api.request(
|
||||||
'/api/v1/settings/publish-pages',
|
API_PUBLISH_PAGES,
|
||||||
DataEvent.API_RENDER_PAGES,
|
DataEvent.API_RENDER_PAGES,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
|
|
|
@ -4,7 +4,19 @@ export const REQUEST_TYPE_PUT = 'PUT';
|
||||||
export const REQUEST_TYPE_DELETE = 'DELETE';
|
export const REQUEST_TYPE_DELETE = 'DELETE';
|
||||||
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';
|
||||||
import * as DataEvent from '../events/DataEvent';
|
export const API_STATUS = '/api/v1/auth/status';
|
||||||
|
export const API_LOGIN = '/api/v1/auth/login';
|
||||||
|
export const API_GET_NAV = '/api/settings/nav';
|
||||||
|
export const API_NEW_PAGE = '/api/v1/page/write/new';
|
||||||
|
export const API_EDIT_PAGE = '/api/v1/page/write';
|
||||||
|
export const API_DELETE_PAGE = '/api/v1/page/delete';
|
||||||
|
export const API_IMAGE_UPLOAD = '/api/v1/page/add-post-image';
|
||||||
|
export const API_SETTINGS_SYNC = '/api/v1/settings/sync';
|
||||||
|
export const API_UPLOAD_AVATAR = '/api/v1/settings/add-avatar';
|
||||||
|
export const API_UPLOAD_BACKGROUND = '/api/v1/settings/add-feature-background';
|
||||||
|
export const API_PUBLISH_PAGES = '/api/v1/settings/publish-pages';
|
||||||
|
export const API_NAV_SYNC = '/api/v1/settings/nav-sync';
|
||||||
|
import * as DataEvent from '../com/events/DataEvent';
|
||||||
export default class APIUtils {
|
export default class APIUtils {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// constructor
|
// constructor
|
||||||
|
@ -12,6 +24,8 @@ export default class APIUtils {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.percentComplete = 0;
|
this.percentComplete = 0;
|
||||||
this.token = null;
|
this.token = null;
|
||||||
|
//checks backend to see if user is logged in
|
||||||
|
//and requests encrypted token for api calls
|
||||||
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) {
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue