--- /dev/null
+'use strict';
+
+alloWebadminControllers
+ .controller('VersionListCtrl', ['$scope', '$routeParams', '$http', 'Version',
+ function ($scope, $routeParams, $http, Version) {
+ $scope.totalVersions = 0;
+ $scope.versions = [];
+ $scope.versionsPerPage = 10;
+ $scope.itemsPerPage = $scope.versionsPerPage;
+ $scope.orderProp = 'value';
+ $scope.versions = [];
+ getResultsPage(1);
+
+ $scope.pagination = {
+ current: 1
+ };
+
+ $scope.pageChanged = function() {
+ getResultsPage($scope.pagination.current);
+ };
+
+ function getResultsPage(pageNumber) {
+ var offset = (pageNumber-1)*$scope.versionsPerPage;
+ if(offset == null || offset == undefined || offset < 0) {
+ offset = 0;
+ }
+ Version.all({limit:$scope.versionsPerPage, offset:offset}).$promise.then(function(data) {
+ $scope.versions = data;
+ });
+ Version.nb().$promise.then(function(data) {
+ $scope.totalVersions = data;
+ $scope.totalItems = $scope.totalVersions.result;
+ });
+ }
+ }])
+ .controller('VersionDetailCtrl', ['$scope', '$routeParams', '$http', 'Version', 'Patch', 'Product', '$uibModal',
+ function ($scope, $routeParams, $http, Version, Patch, Product, $uibModal) {
+ $scope.channels = [];
+ $scope.patches = [];
+ $scope.versionsFrom = [];
+ $scope.patchesUrl = [];
+ $scope.previousPage = {
+ message: "Liste des versions",
+ url: "/#/versions"
+ };
+ getAll();
+
+ function getAll() {
+ var version_id = $routeParams.version_id;
+ Version.info({id:version_id}).$promise.then(function(data) {
+ $scope.version = data.result;
+ $scope.message = data.message;
+ $scope.retour = data.retour;
+ $scope.newPatch = {
+ version_id_from: 0,
+ version_id_to: version_id,
+ script_content: '',
+ script_name: ''
+ };
+ getChannelsForVersion(version_id);
+ getPatchesForVersion(version_id);
+ getVersionsForProduct($scope.version.product);
+ getProductInfo($scope.version.product);
+ });
+ }
+
+ $scope.deletePatch = function(id) {
+ if(id != null && id != undefined && id > 0) {
+ Patch.delete({id:id}).$promise.then(function(data) {
+ $scope.response = data;
+ getAll();
+ });
+ }
+ };
+
+ $scope.patchCreateLaunched = function() {
+ $scope.showAddForm = true;
+
+ var dialogOpts = {
+ animation: true,
+ templateUrl: 'partials/patch-add.html',
+ controller: ['$scope', '$uibModalInstance', 'parentScope',
+ function($scope, $modalInstance, parentScope) {
+ $scope.allo_server_url = parentScope.allo_server_url;
+ $scope.newPatch = parentScope.newPatch;
+ $scope.version = parentScope.version;
+ $scope.versionsFrom = parentScope.versionsFrom;
+ $scope.validate = function() {
+ $modalInstance.close();
+ parentScope.patchCreated();
+ };
+ $scope.cancel = function() {
+ $modalInstance.dismiss('cancel');
+ parentScope.actionCanceled();
+ };
+ }
+ ],
+ resolve: {
+ parentScope: function() {
+ return $scope;
+ }
+ },
+ size: 'lg'
+ };
+
+ $uibModal.open(dialogOpts);
+ };
+
+ $scope.actionCanceled = function() {
+ $scope.showEditForm = 0;
+ $scope.showAddForm = false;
+ };
+
+ $scope.patchCreated = function() {
+ var patchCreationFormEl = document.getElementById("patchCreationForm"),
+ formData = new FormData(patchCreationFormEl),
+ reader = new FileReader(),
+ element = document.getElementById("patch_script"),
+ requestConfig = {headers: {'Content-Type': ""}};
+
+ reader.readAsBinaryString(element.files[0]);
+ reader.onload = function() {
+ $scope.newPatch.script_content = reader.result;
+ $scope.newPatch.script_name = element.files[0].name;
+ formData.set('script_name', $scope.newPatch.script_name);
+ $scope.$apply();
+
+ $http.post($scope.allo_server_url+'?action=patch_edit', formData, requestConfig)
+ .then(function(data) {
+ $scope.response = data;
+ $scope.showAddForm = false;
+ getAll();
+ });
+ };
+ };
+
+ function getChannelsForVersion(id) {
+ Version.get_channels({version_id: id}).$promise.then(function(data) {
+ $scope.channels[id] = data;
+ });
+ }
+
+ function getPatchesForVersion(id) {
+ Version.get_patches({version_id_to: id}).$promise.then(function(data) {
+ $scope.patches[id] = data;
+ getVersionsFrom(id);
+ for(var item in data.result) {
+ //noinspection JSUnfilteredForInLoop
+ createPatchUrl(data.result[item]);
+ }
+ });
+ }
+
+ function createPatchUrl(patch) {
+ Patch.content({id: patch.id}).$promise.then(function(data) {
+ var blob = new Blob([ data ], { type : 'text/plain' });
+ //noinspection JSUnresolvedVariable,JSUnresolvedFunction
+ $scope.patchesUrl[patch.id] = (window.URL || window.webkitURL).createObjectURL( blob );
+ });
+ }
+
+ function getVersionsFrom(id) {
+ for(var item in $scope.patches[id].result) {
+ //noinspection JSUnfilteredForInLoop
+ var patch = $scope.patches[id].result[item];
+ Version.info({id:patch.version_id_from}).$promise.then(function(data) {
+ //noinspection JSReferencingMutableVariableFromClosure
+ $scope.versionsFrom[patch.id] = data;
+ });
+ }
+ }
+
+ function getVersionsForProduct(id) {
+ Version.all({product_id:id}).$promise.then(function(data) {
+ $scope.versionsFrom = data;
+ });
+ }
+
+ function getProductInfo(product_id) {
+ Product.info({id: product_id}).$promise.then(function(data) {
+ $scope.product = data.result;
+ if($scope.product != undefined) {
+ $scope.previousPage.message ="Liste des versions du produit "+$scope.product.name;
+ $scope.previousPage.url = "/#/products/"+$scope.product.id;
+ }
+ });
+ }
+
+ }]
+ );
\ No newline at end of file