updated AdminAPI for remote use, removed UtilityAPI from public library (methods should only be local)

This commit is contained in:
Ro 2021-06-27 13:48:17 -07:00
parent b9056b64df
commit 2785ef6982
5 changed files with 33 additions and 30 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,6 @@
import FipamoAdminAPI from "../libraries/FipamoAdminAPI";
import FipamoUtilityAPI from "../libraries/FipamoUtilityAPI";
//import FipamoUtilityAPI from "../libraries/FipamoUtilityAPI";
import Maintenance from "./controllers/MaintenanceManager";
import DataUitls from "./utils/DataUtils";
import * as DataEvent from "./events/DataEvent";
import DashManager from "./controllers/DashManager";
@ -90,10 +91,9 @@ export default class Base {
e.stopPropagation();
e.preventDefault();
let setUpForm = data.formDataToJSON(document.getElementById("init-form"));
let api = new FipamoUtilityAPI();
let mm = new Maintenance();
this.processing = true;
api
.create(setUpForm)
mm.create(setUpForm)
.then((response) => {
if (response.type === DataEvent.API_INIT_LAME) {
self.processing = false;
@ -117,11 +117,10 @@ export default class Base {
let self = this;
e.stopPropagation();
e.preventDefault();
let api = new FipamoUtilityAPI();
let mm = new Maintenance();
var form = document.getElementById("init-restore");
this.processing = true;
api
.restore(form)
mm.restore(form)
.then((response) => {
if (response.type === DataEvent.REQUEST_LAME) {
self.processing = false;
@ -144,15 +143,14 @@ export default class Base {
e.stopPropagation();
e.preventDefault();
let self = this;
let api = new FipamoUtilityAPI();
let mm = new Maintenance();
if (e.target.id == "get-secret-btn") {
let data = {
email: document.getElementById("email").value,
task: "retrieveSecret"
};
this.processing = true;
api
.secret(data)
mm.secret(data)
.then((response) => {
self.processing = false;
if (response.secret) {
@ -176,8 +174,7 @@ export default class Base {
newPassConfirm: document.getElementById("new_password2").value,
secret: document.getElementById("secret").value
};
api
.newPass(data)
mm.newPass(data)
.then((response) => {
self.processing = false;
if (response.type == "passNotCreated") {

View file

@ -27,7 +27,6 @@ export const TASK_RESET_PASS = "resetPassword";
export const TASK_UPLOAD_FILES = "uploadFiles";
/**
* Fipamo Utility API
* A tub of methods for creating/restoring installs, resetting passwords and uploading images.
*/
class FipamoUtilityAPI {

View file

@ -4,7 +4,7 @@ import FipamoAdminAPI, {
TASK_PAGE_EDIT,
TASK_PAGE_DELETE
} from "../../libraries/FipamoAdminAPI";
import FipamoUtilityAPI from "../../libraries/FipamoUtilityAPI";
import Maintenance from "MaintenanceManager";
import * as DataEvent from "../events/DataEvent";
import PageActions from "../actions/PageActions";
import * as EditorEvent from "../events/EditorEvent";
@ -250,9 +250,8 @@ export default class PostEditor {
handleImageUpload(type, files) {
let self = this;
notify.alert("Uploading Image", null);
let utils = new FipamoUtilityAPI();
utils
.imageUpload(type, files)
let mm = new Maintenance();
mm.imageUpload(type, files)
.then((r) => {
if (r.type == DataEvent.POST_IMAGE_ADDED)
self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url);

View file

@ -32,13 +32,14 @@ export const API_ACCESS_GOOD = "apiConnected";
export const API_ACCESS_BAD = "apiNotConnected";
/**
* Fipamo Administration API
* A pocket full of methods used to edit install settings, navigation pages.
* A can of methods used to edit install settings, navigation pages.
*/
class FipamoAdminAPI {
/**
* @constructor
* @param {string} baseURL - url of site; uses local when empty
* @param {string} key - user api key
*/
constructor(baseURL = null, key = null) {
this.percentComplete = 0; //for later
@ -58,9 +59,9 @@ class FipamoAdminAPI {
}
/**
* Method for retrieving user authorizing user login
* @param {object} data - json object that contains data for set up
* @property {string} handle - handle for site user
* @property {string} password - password for site user
* @param {object} data - json object that contains data for set up
*/
login(data) {
return new Promise((resolve, reject) => {
@ -108,7 +109,7 @@ class FipamoAdminAPI {
syncSettings(data) {
return new Promise((resolve, reject) => {
this._request(
API_SETTINGS_SYNC,
this.baseURL ? this.baseURL + API_SETTINGS_SYNC : API_SETTINGS_SYNC,
TASK_SETTINGS_WRITE,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
@ -131,7 +132,8 @@ class FipamoAdminAPI {
publishSite(data) {
return new Promise((resolve, reject) => {
this._request(
API_PUBLISH_PAGES,
//API_PUBLISH_PAGES,
this.baseURL ? this.baseURL + API_PUBLISH_PAGES : API_PUBLISH_PAGES,
TASK_PUBLISH_SITE,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
@ -189,7 +191,13 @@ class FipamoAdminAPI {
}
return new Promise((resolve, reject) => {
this._request(url, event, REQUEST_TYPE_POST, content, data)
this._request(
this.baseURL ? this.baseURL + url : url,
event,
REQUEST_TYPE_POST,
content,
data
)
.then((result) => {
resolve(result);
})
@ -210,7 +218,7 @@ class FipamoAdminAPI {
syncNav(data) {
return new Promise((resolve, reject) => {
this._request(
API_NAV_SYNC,
this.baseURL ? this.baseURL + API_NAV_SYNC : API_NAV_SYNC,
TASK_SETTINGS_WRITE,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
@ -232,7 +240,7 @@ class FipamoAdminAPI {
sendMail(message) {
return new Promise((resolve, reject) => {
this._request(
API_SEND_MAIL,
this.baseURL ? this.baseURL + API_SEND_MAIL : API_SEND_MAIL,
TASK_SEND_MAIL,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,
@ -253,7 +261,7 @@ class FipamoAdminAPI {
reindexPages(data) {
return new Promise((resolve, reject) => {
this._request(
API_REINDEX_PAGES,
this.baseURL ? this.baseURL + API_REINDEX_PAGES : API_REINDEX_PAGES,
TASK_REINDEX_PAGE,
REQUEST_TYPE_POST,
CONTENT_TYPE_JSON,