1
0
mirror of https://github.com/Foltik/Shimapan synced 2025-01-05 15:58:03 -05:00

Rename api in panel to keys

This commit is contained in:
Jack Foltz 2018-08-14 05:13:59 -04:00
parent 520fb5299d
commit 189a438028
Signed by: foltik
GPG Key ID: 303F88F996E95541
6 changed files with 47 additions and 70 deletions

View File

@ -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();

View File

@ -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'

View File

@ -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;

View File

@ -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);
});
};
}]);

View File

@ -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);
});
};
}]);