1
0
mirror of https://github.com/Foltik/Shimapan synced 2025-01-07 08:42:49 -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'); 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"] // Transforms an array of period-separated properties ex. ["file.upload", "user.view", "user.ban"]
// to json ex. { "file": "upload", "user": ["view", "ban"] } // to json ex. { "file": "upload", "user": ["view", "ban"] }
function splitScope(scope) { 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. // Called on init, retrieves the user's scope from the server.
$scope.parseScope = function () { $scope.parseScope = function () {
AuthService.currentUser(function (res) { AuthService.whoami(function (res) {
$scope.scopeObj = splitScope(res.scope); $scope.scopeObj = splitScope(res.scope);
$scope.currKeyScope = []; $scope.currKeyScope = [];
}) })
@ -38,13 +38,13 @@ angular.module('ApiCtrl', ['ApiSvc', 'AuthSvc']).controller('ApiController', ['$
}; };
$scope.getKeys = function () { $scope.getKeys = function () {
ApiService.getAllKeys(function (keys) { KeyService.getAllKeys(function (keys) {
$scope.keys = keys; $scope.keys = keys;
}); });
}; };
$scope.deleteKey = function (key) { $scope.deleteKey = function (key) {
ApiService.deleteKey(key, function () { KeyService.deleteKey(key, function () {
var index = $scope.keys.indexOf(key); var index = $scope.keys.indexOf(key);
$scope.keys.splice(index, 1); $scope.keys.splice(index, 1);
$scope.hideKeyInfo(); $scope.hideKeyInfo();
@ -56,10 +56,8 @@ angular.module('ApiCtrl', ['ApiSvc', 'AuthSvc']).controller('ApiController', ['$
if ($scope.currKeyScope.length === 0 || !$scope.currKeyIdentifier) if ($scope.currKeyScope.length === 0 || !$scope.currKeyIdentifier)
return; return;
ApiService.createKey({ KeyService.createKey($scope.currKeyIdentifier, $scope.currKeyScope,
identifier: $scope.currKeyIdentifier, function (res) {
scope: JSON.stringify($scope.currKeyScope)
}, function (res) {
if (res.key) { if (res.key) {
$scope.hideNewKey(); $scope.hideNewKey();
$scope.getKeys(); $scope.getKeys();

View File

@ -12,9 +12,9 @@ angular.module('PanelRoutes', ['ui.router']).config(['$stateProvider', '$urlRout
}).state('search', { }).state('search', {
url: '/panel/search', url: '/panel/search',
templateUrl: '/views/panel/search.html' templateUrl: '/views/panel/search.html'
}).state('api', { }).state('keys', {
url: '/panel/api', url: '/panel/keys',
templateUrl: '/views/panel/api.html' templateUrl: '/views/panel/keys.html'
}).state('invites', { }).state('invites', {
url: '/panel/invites', url: '/panel/invites',
templateUrl: '/views/panel/invites.html' templateUrl: '/views/panel/invites.html'

View File

@ -1,6 +1,6 @@
var angular = require('angular'); var angular = require('angular');
var uirouter = require('angular-ui-router'); 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) { app.run(['$rootScope', '$state', '$stateParams', function($rootScope, $state, $stateParams) {
$rootScope.$state = $state; $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);
});
};
}]);