-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug 1310214: UI for scheduled changes of Releases (#205). r=bhearsum
- Loading branch information
Showing
18 changed files
with
944 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
ui/app/js/controllers/release_scheduled_change_delete_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
angular.module("app").controller("DeleteReleaseScheduledChangeCtrl", | ||
function ($scope, $modalInstance, CSRF, Releases, sc, scheduled_changes) { | ||
|
||
$scope.sc = sc; | ||
$scope.scheduled_changes = scheduled_changes; | ||
$scope.saving = false; | ||
|
||
$scope.saveChanges = function () { | ||
$scope.saving = true; | ||
CSRF.getToken() | ||
.then(function(csrf_token) { | ||
Releases.deleteScheduledChange($scope.sc.sc_id, $scope.sc, csrf_token) | ||
.success(function(response) { | ||
$scope.scheduled_changes.splice($scope.scheduled_changes.indexOf($scope.sc), 1); | ||
$modalInstance.close(); | ||
}) | ||
.error(function(response) { | ||
if (typeof response === 'object') { | ||
sweetAlert( | ||
{ | ||
title: "Form submission error", | ||
text: response.exception | ||
}, | ||
function() { $scope.cancel(); } | ||
); | ||
} | ||
}) | ||
.finally(function() { | ||
$scope.saving = false; | ||
}); | ||
}); | ||
}; | ||
|
||
$scope.cancel = function () { | ||
$modalInstance.dismiss("cancel"); | ||
}; | ||
}); |
134 changes: 134 additions & 0 deletions
134
ui/app/js/controllers/release_scheduled_change_edit_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
|
||
angular.module('app').controller('EditReleaseScheduledChangeCtrl', | ||
function ($scope, $modalInstance, CSRF, Releases, sc) { | ||
|
||
$scope.is_edit = true; | ||
$scope.original_sc = sc; | ||
$scope.sc = angular.copy(sc); | ||
$scope.products = []; | ||
Releases.getProducts().success(function(response) { | ||
$scope.products = response.product; | ||
}); | ||
|
||
$scope.errors = {}; | ||
$scope.saving = false; | ||
|
||
$scope.setWhen = function(newDate) { | ||
if (!newDate) { | ||
newDate = new Date($("#id_when")[0].value); | ||
$scope.sc.when = newDate; | ||
} | ||
$scope.calendar_is_open = false; | ||
if (newDate <= new Date()) { | ||
$scope.errors.when = ["Scheduled time cannot be in the past"]; | ||
$scope.sc.when = $scope.original_sc.when; | ||
} | ||
else { | ||
$scope.errors.when = null; | ||
} | ||
}; | ||
|
||
$scope.clearWhen = function () { | ||
$scope.sc.when = null; | ||
$scope.errors.when = null; | ||
}; | ||
|
||
$scope.fillName = function () { | ||
var file = $scope.dataFile; | ||
$scope.errors.data = []; | ||
var reader = new FileReader(); | ||
reader.onloadend = function(evt) { | ||
var blob = evt.target.result; | ||
$scope.$apply( function() { | ||
try { | ||
var name = JSON.parse(blob).name; | ||
if(!name) { | ||
$scope.errors.data = ["Form submission error", "Name missing in blob.\n"]; | ||
} | ||
else if (name !== $scope.sc.name) { | ||
$scope.errors.data = ["Form submission error", "Name differs compared to name in blob.\n"]; | ||
} | ||
} catch(err) { | ||
$scope.errors.data = ["Form submission error", "Malformed JSON file.\n"]; | ||
} | ||
}); | ||
if ($scope.errors.data.length === 0) { | ||
$scope.sc.data = blob; | ||
} | ||
}; | ||
if (typeof file !== 'undefined') { | ||
// should work | ||
reader.readAsText(file); | ||
} | ||
}; | ||
|
||
$scope.changeName = function () { | ||
//wait for actual file to be loaded | ||
setTimeout($scope.fillName, 0); | ||
}; | ||
|
||
$scope.saveChanges = function () { | ||
if ($scope.sc.change_type !== "delete") { | ||
if (!$scope.sc.product.trim()) { | ||
sweetAlert( | ||
"Form Error", | ||
"Product is required.", | ||
"error" | ||
); | ||
return; | ||
} | ||
|
||
if (!$scope.sc.name.trim()) { | ||
sweetAlert( | ||
"Form Error", | ||
"Name is required", | ||
"error" | ||
); | ||
return; | ||
} | ||
|
||
if (!$scope.dataFile) { | ||
delete $scope.sc.data; | ||
} | ||
} | ||
|
||
$scope.saving = true; | ||
|
||
CSRF.getToken() | ||
.then(function(csrf_token) { | ||
Releases.updateScheduledChange($scope.sc.sc_id, $scope.sc, csrf_token) | ||
.success(function(response) { | ||
$scope.sc.sc_data_version = response.new_data_version; | ||
angular.copy($scope.sc, $scope.original_sc); | ||
$scope.saving = false; | ||
$modalInstance.close(); | ||
}) | ||
.error(function(response) { | ||
if (typeof response === 'object') { | ||
$scope.errors = response; | ||
sweetAlert( | ||
"Form submission error", | ||
"See fields highlighted in red.", | ||
"error" | ||
); | ||
} | ||
else if (typeof response === 'string') { | ||
// quite possibly an error in the blob validation | ||
sweetAlert( | ||
"Form submission error", | ||
"Unable to submit successfully.\n" + | ||
"(" + response+ ")", | ||
"error" | ||
); | ||
} | ||
}) | ||
.finally(function() { | ||
$scope.saving = false; | ||
}); | ||
}); | ||
}; // /saveChanges | ||
|
||
$scope.cancel = function () { | ||
$modalInstance.dismiss('cancel'); | ||
}; | ||
}); |
Oops, something went wrong.