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:
parent
520fb5299d
commit
189a438028
@ -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();
|
@ -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'
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
});
|
||||
};
|
||||
}]);
|
37
app/public/services/KeySvc.js
Normal file
37
app/public/services/KeySvc.js
Normal 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);
|
||||
});
|
||||
};
|
||||
}]);
|
Loading…
Reference in New Issue
Block a user