Add image creation and suppression

This commit is contained in:
Loic GUEGAN 2016-05-06 14:24:15 +02:00
parent 664cddd4fa
commit 2856a776db
9 changed files with 107 additions and 47 deletions

View file

@ -26,7 +26,7 @@
<div ng-include="'./partials/home/machineDetails.html'"></div> <div ng-include="'./partials/home/machineDetails.html'"></div>
<div ng-include="'./partials/home/machineCreation.html'"></div> <div ng-include="'./partials/home/machineCreation.html'"></div>
<div ng-include="'./partials/loading.html'"></div> <div ng-include="'./partials/loading.html'"></div>
<div ng-include="'./partials/image/upload.html'"></div> <div ng-include="'./partials/image/create.html'"></div>
<div ng-include="'./partials/image/edit.html'"></div> <div ng-include="'./partials/image/edit.html'"></div>
@ -97,7 +97,7 @@
<script src="./js/controllers/home/machineCreation.js"></script> <script src="./js/controllers/home/machineCreation.js"></script>
<script src="./js/controllers/network/network.js"></script> <script src="./js/controllers/network/network.js"></script>
<script src="./js/controllers/image/image.js"></script> <script src="./js/controllers/image/image.js"></script>
<script src="./js/controllers/image/upload.js"></script> <script src="./js/controllers/image/create.js"></script>
<script src="./js/controllers/image/edit.js"></script> <script src="./js/controllers/image/edit.js"></script>

View file

@ -3,7 +3,7 @@
* *
* @param {$scope} $scope The $scope service from angular * @param {$scope} $scope The $scope service from angular
*/ */
mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload', function ($scope, Image, Loading, Identity, upload) mainApp.controller('createImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', 'upload','$rootScope', function ($scope, Image, Loading, Identity, upload, $rootScope)
{ {
/*$scope.uploader = new FileUploader({ /*$scope.uploader = new FileUploader({
"token" : Identity.getToken(), "token" : Identity.getToken(),
@ -22,11 +22,11 @@ mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity',
*/ */
$scope.doUpload = function () { $scope.doUpload = function () {
/* console.log($('#imageToUpload').prop('files')[0]); /* console.log($('#imageToUpload').prop('files')[0]);
Image.uploadImage($('#imageToUpload').prop('files')[0], function () { Image.uploadImage($('#imageToUpload').prop('files')[0], function () {
alert("done"); alert("done");
});*/ });*/
Image.uploadImage("loic",function(){}) Image.uploadImage("loic", function () {})
/*$("#drop-area-div").dmUploader({ /*$("#drop-area-div").dmUploader({
extraData: { extraData: {
"token" : Identity.getToken(), "token" : Identity.getToken(),
@ -59,10 +59,22 @@ mainApp.controller('uploadImageCtrl', ['$scope', 'Image', 'Loading', 'Identity',
}; };
// Manager logout event // Manager logout event
$scope.$on('showUploadImageModalEvent', function () { $scope.$on('showCreateImageModalEvent', function () {
$scope.token = Identity.getToken(); $scope.token = Identity.getToken();
$('#uploadImageModal').modal("show"); $('#createImageModal').modal("show");
}); });
var callMeAfterImageCreate = function (response) {
$rootScope.$broadcast("updateImageEvent");
Loading.stop();
}
$scope.doCreation = function () {
$('#createImageModal').modal("hide");
Loading.start();
Image.createImage($scope.name, callMeAfterImageCreate)
};
}]); }]);

View file

@ -9,7 +9,6 @@ mainApp.controller('editImageCtrl', ['$scope', 'Image', 'Loading', 'Identity', '
$scope.image = image; $scope.image = image;
$scope.axioms = axioms; $scope.axioms = axioms;
$('#editImageModal').modal('show'); $('#editImageModal').modal('show');
console.log(image)
}); });
$scope.data = {}; $scope.data = {};
$scope.data.visibility = "public"; $scope.data.visibility = "public";

View file

@ -22,13 +22,29 @@ mainApp.controller('imageCtrl', ['$scope', 'Image', 'Loading', 'Identity', '$roo
} }
} }
// Manager logout event
$scope.$on('updateImageEvent', function () {
// If user is login try to retrieve data
if (Identity.isAlreadyLogin()) {
Loading.start();
Image.getImages(callMeAfterGetImage);
}
});
$scope.edit = function (image) { $scope.edit = function (image) {
$rootScope.$broadcast("editImageEvent", image, Image.getData().axioms); $rootScope.$broadcast("editImageEvent", image, Image.getData().axioms);
} }
$scope.showUploadImageModal = function () { $scope.showCreateImageModal = function () {
$rootScope.$broadcast("showUploadImageModalEvent"); $rootScope.$broadcast("showCreateImageModalEvent");
}; };
$scope.deleteImage = function (id) {
Image.deleteImage(id, function () {
$rootScope.$broadcast("updateImageEvent");
})
}
}]); }]);

View file

@ -148,6 +148,23 @@ mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) {
callback() callback()
}); });
}; };
var deleteImage = function (id,callback) {
var result = $http.post('../server/index.php',
$.param({"token": Identity.getToken(), "task": "image", 'action': 'deleteImage', "id":id}));
//var result=$http.post('../server/index.php',
// $.param({"token" : Identity.getToken(), "task" : "image", 'action':'uploadImage', 'file_name':form_data, 'id':'6564'}));
// Wait and handle the response
result.then(function (response) {
callback()
}, function (response) {
alert(response.data)
callback()
});
};
@ -160,6 +177,7 @@ mainApp.factory('Image', ['$http', 'Identity', function ($http, Identity) {
getImages: getImages, getImages: getImages,
updateImage: updateImage, updateImage: updateImage,
getData: getData, getData: getData,
deleteImage:deleteImage,
createImage: createImage, createImage: createImage,
uploadImage: uploadImage uploadImage: uploadImage
}; };

View file

@ -0,0 +1,33 @@
<div class="modal fade" id="createImageModal" ng-controller="createImageCtrl">
<div class="modal-dialog">
<div class="modal-content"></div>
</div>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>-->
<h4 class="modal-title">Upload Image</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="control-label col-sm-2">Name</label>
<div class="col-sm-20">
<input ng-model="name" type="text" value="" />
</div>
</div>
</form>
<div class="modal-footer">
<!--<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>-->
<a class="btn btn-lg btn-primary btn-block" id="loginButton" ng-click="doCreation()">Create</a>
</div>
</div>
</div>
</div>

View file

@ -34,6 +34,19 @@
</fieldset> </fieldset>
</form> </form>
<form action="../server/index.php" method="post">
<input type="hidden" name="task" value="image" />
<input type="hidden" name="token" value="{{ token}}" />
<input type="hidden" name="action" value="uploadImage" />
<input type="hidden" name="id" value="60ed9403-419e-4ea8-933f-dd1750d97360" />
<input type="hidden" name="file_name" value="bob.iso" />
<fieldset class="form-group">
<label class="control-label col-sm-2">Upload</label>
<input name="file" type="file" />
<input type="submit" value="Upload" />
</fieldset>
</form>
<div class="modal-footer"> <div class="modal-footer">
<!--<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>--> <!--<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>-->

View file

@ -8,7 +8,7 @@
<div class="btn-group btn-group-md" role="group" aria-label="..."> <div class="btn-group btn-group-md" role="group" aria-label="...">
<button type="button" class="btn btn-default" ng-click="showUploadImageModal()">Upload</button> <button type="button" class="btn btn-default" ng-click="showCreateImageModal()">Create Image</button>
<button type="button" class="btn btn-default">Download</button> <button type="button" class="btn btn-default">Download</button>
</div> </div>
<p></p> <p></p>
@ -30,7 +30,7 @@
<td>{{ (image.size / 1048576).toFixed(2)}} MB</td> <td>{{ (image.size / 1048576).toFixed(2)}} MB</td>
<td> <td>
<button type="button" class="btn btn-primary" ng-click="edit(image)">Edit</button> <button type="button" class="btn btn-primary" ng-click="edit(image)">Edit</button>
<button type="button" class="btn btn-danger">Remove</button> <button type="button" class="btn btn-danger" ng-click="deleteImage(image.id)">Remove</button>
</td> </td>
</tr> </tr>

View file

@ -1,31 +0,0 @@
<div class="modal fade" id="uploadImageModal" ng-controller="uploadImageCtrl">
<div class="modal-dialog">
<div class="modal-content"></div>
</div>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>-->
<h4 class="modal-title">Upload Image</h4>
</div>
<div class="modal-body">
<form action="../server/index.php" method="post">
<input type="hidden" name="task" value="image" />
<input type="hidden" name="token" value="{{ token }}" />
<input type="hidden" name="action" value="uploadImage" />
<input type="hidden" name="id" value="60ed9403-419e-4ea8-933f-dd1750d97360" />
<input type="hidden" name="file_name" value="bob.iso" />
<input name="file" type="file" />
<input type="submit" value="Upload" />
</form>
<div class="modal-footer">
<!--<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>-->
<a class="btn btn-lg btn-primary btn-block" id="loginButton" ng-click="doUpload()">Upload</a>
</div>
</div>
</div>
</div>