Files
portal-webapp/portal_client/app/main/git-bank/git-bank.js
T
2018-07-07 20:43:51 -05:00

151 lines
5.0 KiB
JavaScript

(function () {
'use strict';
/**
* MODULE DESCRIPTION:
*
* TODO: Write description here.
*/
angular.module('portal.dashboard.gitBank', ['ui.router'])
.controller('GitBankCtrl', GitBankCtrlController);
function GitBankCtrlController($scope, cache, gitProvider, gitStores, Constants,
accountStores, $mdDialog, uiGridConstants, portalUtils) {
$scope.confirmQuestionBox = true;
$scope.Permissions = Constants.Permissions;
$scope.repos = [];
$scope.userRole = '';
$scope.dirs = {};
$scope.mCache = cache.request([
new accountStores.Account(),
new gitStores.Repos()
]).then(function(){
$scope.userRole = $scope.mCache.account.data.role;
$scope.repos = $scope.mCache.repos.data.values;
});
$scope.repoGrid = {
data: 'repos',
paginationPageSizes: [25, 50, 75, 100, 125, 150, 175, 200],
paginationPageSize: 25,
enableHorizontalScrollbar: uiGridConstants.scrollbars.NEVER,
toggleModifierKeysToMultiSelect : true,
enableRowHeaderSelection: true,
enableColumnMenus: true,
enableGridMenu: true,
exporterMenuCsv: true,
multiSelect: false,
noUnselect: false,
onRegisterApi: function (gridApi) {
$scope.repoGridApi = gridApi;
},
columnDefs: [
{field: 'name', displayName: 'Name', width: '*'},
{field: 'scm', displayName: 'SCM', width: '**' },
{field: 'branch', displayName: 'Branch', width: '**' },
{field: 'directory', displayName: 'Directory', width: '**' },
{field: 'lastUpdated', displayName: 'Last Updated', width: '**',
cellTemplate: '<div class="ui-grid-cell-contents" >{{grid.appScope.formatTimeLong(row.entity.lastUpdated)}}</div>'},
{field: 'createDate', displayName: 'Create Date', width: '*',
cellTemplate: '<div class="ui-grid-cell-contents" >{{grid.appScope.formatTimeShort(row.entity.createDate)}}</div>'},
{field: 'id', displayName: 'Actions', width: '125', enableColumnMenu: false, enableFiltering: false, enableHiding: false,
cellTemplate: 'main/git-bank/cell-templates/git-actions.html'
}
],
};
$scope.formatTimeLong = function(value) {
return moment(value).format('MM/DD/Y HH:mm:ss');
};
$scope.formatTimeShort = function(value) {
return moment(value).format('MM/DD/Y');
};
$scope.$on('$destroy', function () {
$scope.mCache.unlisten();
});
$scope.toggleFiltering = function() {
$scope.repoGrid.enableFiltering = !$scope.repoGrid.enableFiltering;
$scope.repoGridApi.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
};
$scope.pull = function(entity) {
portalUtils.confirmBox('updateRepo', 'Update Repository', ['Issue a pull request for', entity.name],
true, function(value) {
if (value.confirm) {
gitProvider.pullRepo(entity).then(function() {
portalUtils.toast('Repository updated successfully', ['top', 'left'], 2000);
new gitStores.Repos().refresh();
}).catch(function(err){
portalUtils.toast('Unable to update repository: ' + err.message, ['top', 'left'], 4000);
new gitStores.Repos().refresh();
});
}
});
};
$scope.delete = function(entity) {
if ($scope.confirmQuestionBox) {
portalUtils.confirmBox('deleteRepo', 'Delete Repository', ['Are you sure you want to delete the repository', entity.name],
true, function(value) {
if (value.confirm) {
$scope.confirmQuestionBox = !value.checkbox;
$scope.deleteRepo(entity);
}
});
} else {
$scope.deleteRepo(entity);
}
};
$scope.deleteRepo = function(entity) {
gitProvider.deleteRepo(entity).then(function() {
portalUtils.toast('Repository deleted successfully', ['top', 'left'], 2000);
new gitStores.Repos().refresh();
}).catch(function(err){
portalUtils.toast('Unable to delete repository: ' + err.message, ['top', 'left'], 4000);
new gitStores.Repos().refresh();
});
};
$scope.edit = function(entity) {
$mdDialog.show({
templateUrl: 'common/partials/add-git/add-git.html',
controller: 'AddGitCtrl',
escapeToClose: false,
locals: {
modalInstance: {
header: 'Edit Git Repository',
gitInfo: entity
}
}
}).then(function() {
new gitStores.Repos().refresh();
});
};
$scope.addRepo = function() {
$mdDialog.show({
templateUrl: 'common/partials/add-git/add-git.html',
controller: 'AddGitCtrl',
escapeToClose: false,
locals: {
modalInstance: {
header: 'Add Git Repository',
}
}
}).then(function() {
new gitStores.Repos().refresh();
});
};
} //end GitBankCtrlController function
})();