From 189a43802870e30e8639dd8dae4bf8cca7e092c9 Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Tue, 14 Aug 2018 05:13:59 -0400 Subject: [PATCH] Rename api in panel to keys --- .../panel/controllers/{ApiCtrl.js => KeyCtrl.js} | 14 +++--- app/public/panel/routes.js | 6 +-- app/public/panel/shimapan-panel.js | 2 +- app/public/services/ApiSvc.js | 58 ---------------------- app/public/services/KeySvc.js | 37 ++++++++++++++ public/views/panel/{api.html => keys.html} | 0 6 files changed, 47 insertions(+), 70 deletions(-) rename app/public/panel/controllers/{ApiCtrl.js => KeyCtrl.js} (83%) delete mode 100644 app/public/services/ApiSvc.js create mode 100644 app/public/services/KeySvc.js rename public/views/panel/{api.html => keys.html} (100%) diff --git a/app/public/panel/controllers/ApiCtrl.js b/app/public/panel/controllers/KeyCtrl.js similarity index 83% rename from app/public/panel/controllers/ApiCtrl.js rename to app/public/panel/controllers/KeyCtrl.js index 7700aca..6f31141 100644 --- a/app/public/panel/controllers/ApiCtrl.js +++ b/app/public/panel/controllers/KeyCtrl.js @@ -1,6 +1,6 @@ var angular = require('angular'); -angular.module('ApiCtrl', ['ApiSvc', 'AuthSvc']).controller('ApiController', ['$scope', 'ApiService', 'AuthService', function ($scope, ApiService, AuthService) { +angular.module('KeyCtrl', ['KeySvc', 'AuthSvc']).controller('ApiController', ['$scope', 'KeyService', 'AuthService', function ($scope, KeyService, AuthService) { // Transforms an array of period-separated properties ex. ["file.upload", "user.view", "user.ban"] // to json ex. { "file": "upload", "user": ["view", "ban"] } function splitScope(scope) { @@ -19,7 +19,7 @@ angular.module('ApiCtrl', ['ApiSvc', 'AuthSvc']).controller('ApiController', ['$ // Called on init, retrieves the user's scope from the server. $scope.parseScope = function () { - AuthService.currentUser(function (res) { + AuthService.whoami(function (res) { $scope.scopeObj = splitScope(res.scope); $scope.currKeyScope = []; }) @@ -38,13 +38,13 @@ angular.module('ApiCtrl', ['ApiSvc', 'AuthSvc']).controller('ApiController', ['$ }; $scope.getKeys = function () { - ApiService.getAllKeys(function (keys) { + KeyService.getAllKeys(function (keys) { $scope.keys = keys; }); }; $scope.deleteKey = function (key) { - ApiService.deleteKey(key, function () { + KeyService.deleteKey(key, function () { var index = $scope.keys.indexOf(key); $scope.keys.splice(index, 1); $scope.hideKeyInfo(); @@ -56,10 +56,8 @@ angular.module('ApiCtrl', ['ApiSvc', 'AuthSvc']).controller('ApiController', ['$ if ($scope.currKeyScope.length === 0 || !$scope.currKeyIdentifier) return; - ApiService.createKey({ - identifier: $scope.currKeyIdentifier, - scope: JSON.stringify($scope.currKeyScope) - }, function (res) { + KeyService.createKey($scope.currKeyIdentifier, $scope.currKeyScope, + function (res) { if (res.key) { $scope.hideNewKey(); $scope.getKeys(); diff --git a/app/public/panel/routes.js b/app/public/panel/routes.js index 90a6843..ffcfdd0 100644 --- a/app/public/panel/routes.js +++ b/app/public/panel/routes.js @@ -12,9 +12,9 @@ angular.module('PanelRoutes', ['ui.router']).config(['$stateProvider', '$urlRout }).state('search', { url: '/panel/search', templateUrl: '/views/panel/search.html' - }).state('api', { - url: '/panel/api', - templateUrl: '/views/panel/api.html' + }).state('keys', { + url: '/panel/keys', + templateUrl: '/views/panel/keys.html' }).state('invites', { url: '/panel/invites', templateUrl: '/views/panel/invites.html' diff --git a/app/public/panel/shimapan-panel.js b/app/public/panel/shimapan-panel.js index e92d5fb..a23790c 100644 --- a/app/public/panel/shimapan-panel.js +++ b/app/public/panel/shimapan-panel.js @@ -1,6 +1,6 @@ var angular = require('angular'); var uirouter = require('angular-ui-router'); -var app = angular.module('shimapan-panel', ['ui.router', 'AuthSvc', 'ApiSvc', 'InviteSvc', 'UserSvc', 'ApiCtrl', 'InviteCtrl', 'UserCtrl', 'NavCtrl', 'PanelRoutes']); +var app = angular.module('shimapan-panel', ['ui.router', 'AuthSvc', 'KeySvc', 'InviteSvc', 'UserSvc', 'KeyCtrl', 'InviteCtrl', 'UserCtrl', 'NavCtrl', 'PanelRoutes']); app.run(['$rootScope', '$state', '$stateParams', function($rootScope, $state, $stateParams) { $rootScope.$state = $state; diff --git a/app/public/services/ApiSvc.js b/app/public/services/ApiSvc.js deleted file mode 100644 index a981f22..0000000 --- a/app/public/services/ApiSvc.js +++ /dev/null @@ -1,58 +0,0 @@ -var angular = require('angular'); - -angular.module('ApiSvc', []).service('ApiService', ['$http', function ($http) { - this.getKey = function (identifier, cb) { - $http({ - method: 'GET', - url: '/api/keys/get', - params: {identifier: identifier} - }).then(function (res) { - cb(res.data); - }); - }; - - this.getAllKeys = function (cb) { - $http({ - method: 'GET', - url: '/api/keys/get' - }).then(function (res) { - cb(res.data); - }); - }; - - this.deleteKey = function (key, cb) { - $http({ - method: 'POST', - url: '/api/keys/delete', - headers: {'Content-Type': 'application/x-www-form-urlencoded'}, - transformRequest: function (obj) { - var str = []; - for (var p in obj) - if (obj.hasOwnProperty(p)) - str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); - return str.join("&"); - }, - data: {key: key.key} - }).then(function (res) { - cb(res.data); - }); - }; - - this.createKey = function (key, cb) { - $http({ - method: 'POST', - url: '/api/keys/create', - headers: {'Content-Type': 'application/x-www-form-urlencoded'}, - transformRequest: function (obj) { - var str = []; - for (var p in obj) - if (obj.hasOwnProperty(p)) - str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); - return str.join("&"); - }, - data: key - }).then(function(res) { - cb(res.data); - }); - }; -}]); diff --git a/app/public/services/KeySvc.js b/app/public/services/KeySvc.js new file mode 100644 index 0000000..2394573 --- /dev/null +++ b/app/public/services/KeySvc.js @@ -0,0 +1,37 @@ +var angular = require('angular'); + +angular.module('KeySvc', []).service('KeyService', ['$http', function ($http) { + this.getAllKeys = function (cb) { + $http({ + method: 'GET', + url: '/api/keys/get' + }).then(function (res) { + cb(res.data); + }); + }; + + this.deleteKey = function (key, cb) { + $http({ + method: 'POST', + url: '/api/keys/delete', + data: { + key: key + } + }).then(function (res) { + cb(res.data); + }); + }; + + this.createKey = function (identifier, scope, cb) { + $http({ + method: 'POST', + url: '/api/keys/create', + data: { + identifier: identifier, + scope: scope + } + }).then(function(res) { + cb(res.data); + }); + }; +}]); diff --git a/public/views/panel/api.html b/public/views/panel/keys.html similarity index 100% rename from public/views/panel/api.html rename to public/views/panel/keys.html