Add "create new" button to table of existing rotations

This commit is contained in:
Jan Tuomi
2017-01-12 07:22:30 -05:00
parent 46a4ca5478
commit 4f12c42c5f
5 changed files with 45 additions and 3 deletions
+1
View File
@@ -200,3 +200,4 @@ class ImageUploadForm(forms.Form):
''' '''
name = forms.CharField() name = forms.CharField()
image = forms.ImageField() image = forms.ImageField()
+6 -2
View File
@@ -29,7 +29,12 @@
<td>{{r.name}}</td> <td>{{r.name}}</td>
<td><input type="button" class="btn btn-info" ng-click="selectRotation(r.id)" value="select"></td> <td><input type="button" class="btn btn-info" ng-click="selectRotation(r.id)" value="select"></td>
</tr> </tr>
</table> <tr>
<td><input type="text" ng-model="r.name" placeholder="Name"></input></td>
<td><input type="button" class="btn btn-success" ng-click="createRotation(r.name)" value="create new"></input></td>
</tr>
</table>
<h2>Rotation: {{selected_rot.name}}</h2> <h2>Rotation: {{selected_rot.name}}</h2>
<div>Instances in currently selected rotation:</div> <div>Instances in currently selected rotation:</div>
<table class="table table-striped"> <table class="table table-striped">
@@ -38,7 +43,6 @@
<td>{{i.item.name}}</td><td>{{i.duration}}s</td> <td>{{i.item.name}}</td><td>{{i.duration}}s</td>
<td><input type="button" ng-click="deleteInstance(i.id);" value="delete" class="btn btn-danger"></input><td> <td><input type="button" ng-click="deleteInstance(i.id);" value="delete" class="btn btn-danger"></input><td>
</tr> </tr>
</table
</div> </div>
</div </div
+16 -1
View File
@@ -38,6 +38,12 @@ app.service("InstanceList", ["$http", function($http){
} }
}); });
} }
this.createRotation = function(name) {
data = {'name': name}
console.log(name)
$http.post("/infoscreen/create_rotation", data).then(function(response) {
});
}
this.deleteInstance = function(id){ this.deleteInstance = function(id){
$http.delete("/infoscreen/instance/"+id).then(function(response){ $http.delete("/infoscreen/instance/"+id).then(function(response){
self.getRotation(self.selected_rot.id); self.getRotation(self.selected_rot.id);
@@ -67,7 +73,7 @@ app.service("ItemList", ["$http",'InstanceList', function($http, InstanceList){
}; };
}]); }]);
app.controller('infoadmin_ctrl', function($scope, $http, ItemList, InstanceList){ app.controller('infoadmin_ctrl', function($scope, $http, $window, ItemList, InstanceList){
// init items // init items
$scope.rotations = []; $scope.rotations = [];
$scope.infoitems = []; $scope.infoitems = [];
@@ -75,6 +81,15 @@ app.controller('infoadmin_ctrl', function($scope, $http, ItemList, InstanceList)
// helpers // helpers
$scope.deleteItem = ItemList.deleteItem; $scope.deleteItem = ItemList.deleteItem;
$scope.selectRotation = InstanceList.getRotation; $scope.selectRotation = InstanceList.getRotation;
/* Create a new rotation from with the user-provided name
* We also want to reload the page afterwards to refresh the table
* If the table were implemented with ng-table we could just refresh that but at the moment
* it's not so we just fullblast the whole thing */
$scope.createRotation = function(name) {
InstanceList.createRotation(name);
$window.location.reload();
};
$scope.createInstance = InstanceList.createInstance; $scope.createInstance = InstanceList.createInstance;
$scope.deleteInstance = InstanceList.deleteInstance; $scope.deleteInstance = InstanceList.deleteInstance;
// fetch data // fetch data
+20
View File
@@ -12,6 +12,7 @@ from infoscreen.models import ImageUploadForm
from datetime import datetime, timedelta from datetime import datetime, timedelta
import json import json
import logging
def index(request,idx, *args, **kwargs): def index(request,idx, *args, **kwargs):
return render(request, 'infoscreen_index.html',{'rotation':idx}) return render(request, 'infoscreen_index.html',{'rotation':idx})
@@ -135,6 +136,25 @@ def createImageItem(request, *args, **kwargs):
ImageInfoItem.objects.create(img=img, name=name) ImageInfoItem.objects.create(img=img, name=name)
return HttpResponse('{"status":"success"}') return HttpResponse('{"status":"success"}')
@require_http_methods(["POST"])
@ensure_csrf_cookie
@permission_required('infoscreen.add_rotation', login_url='/login')
def createRotation(request, *args, **kwargs):
try:
data = json.loads(request.body.decode("utf-8"))
except:
return HttpResponse('{"error": "bad post body!"}', status=400)
try:
name = data["name"]
Rotation.objects.create(name=name)
resp = HttpResponse(status=200)
except:
resp = HttpResponse('{"error" : "could not create rotation!"}', status=400)
return resp
createInstance = itemCreator(InfoInstance) createInstance = itemCreator(InfoInstance)
deleteInstance = itemDeletor(InfoInstance) deleteInstance = itemDeletor(InfoInstance)
createABBItem = itemCreator(ABBInfoItem) createABBItem = itemCreator(ABBInfoItem)
+2
View File
@@ -44,6 +44,7 @@ from infoscreen.views import createExternalImageInfoItem
from infoscreen.views import createImageItem from infoscreen.views import createImageItem
from infoscreen.views import createABBItem from infoscreen.views import createABBItem
from infoscreen.views import createSossoItem from infoscreen.views import createSossoItem
from infoscreen.views import createRotation
from infoscreen.views import admin as infoscreen_admin from infoscreen.views import admin as infoscreen_admin
#application #application
from members.views import applicationindex from members.views import applicationindex
@@ -82,6 +83,7 @@ urlpatterns = [
url(r'^infoscreen/create_abbitem$', createABBItem), url(r'^infoscreen/create_abbitem$', createABBItem),
url(r'^infoscreen/create_sossoitem$', createSossoItem), url(r'^infoscreen/create_sossoitem$', createSossoItem),
url(r'^infoscreen/admin$', infoscreen_admin), url(r'^infoscreen/admin$', infoscreen_admin),
url(r'^infoscreen/create_rotation$', createRotation),
#application #application
url(r'^application/$', applicationindex), url(r'^application/$', applicationindex),
url(r'^application/success$', applicationSuccessIndex), url(r'^application/success$', applicationSuccessIndex),