Skip to content

Commit

Permalink
Work on renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanBluth committed Mar 9, 2016
1 parent ba23577 commit 2b04b41
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions scenarioEditor/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
url(r'^service/post_process_component_set/', scenarioEditor.views.post_process_component_set_service, name='post_process_component_set_service'),
url(r'^service/dump_data/', scenarioEditor.views.dump_data_service, name='dump_data_service'),
url(r'^service/delete_scenario/(?P<scenario_id>[0-9]+)/$', scenarioEditor.views.delete_scenario_service, name='delete_scenario_service'),
url(r'^service/rename_scenario/(?P<scenario_id>[0-9]+)/$', scenarioEditor.views.rename_scenario_service, name='rename_scenario_service'),
)
25 changes: 25 additions & 0 deletions scenarioEditor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,31 @@ def delete_scenario_service(request, scenario_id):
return HttpResponse("Invalid Method", status=405)


@csrf_exempt
@login_required(login_url='/scenario/login/')
def rename_scenario_service(request, scenario_id):
if request.method == 'POST':
payload = json.loads(request.body)
if scenario_id is not None and 'name' in payload:
scenario = Scenario.objects.get(id=scenario_id)
pd_user = PDUser.objects.get(user=request.user)
if scenario.owner.id == pd_user.id:
old_file_name = scenario.jsonUrl
scenario.name = payload['name']
scenario.jsonUrl = "scenarios/" + scenario.name.replace(" ", "_") + ".json"
gitlab_utility.delete_file(old_file_name, PDUser.branch_for_user(user=request.user))
gitlab_utility.create_file(gitlab_utility.get_project_name(), PDUser.branch_for_user(user=request.user),
scenario.jsonUrl, scenario.script, "text")
dump_scenarios(request)
return HttpResponse()
else:
return HttpResponse("Unauthorized", status=401)
else:
return HttpResponse("Bad Request", status=400)
else:
return HttpResponse("Invalid Method", status=405)


@login_required(login_url='/scenario/login/')
def create_scenario_view(request):
if request.method == 'GET':
Expand Down
13 changes: 13 additions & 0 deletions static/js/scenarioEditor/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,19 @@ scenarioEditor.controller('EditorCtrl', ['$scope', '$http', 'convoService', 'cha
}
};

$scope.rename = function(id){
blockUi(true);
$http.post('/scenario/service/rename_scenario/' + id + "/", {name:$scope.scenarioName}).then(
function(data){
blockUi(false)
},
function (data){
blockUi(false);
alert("Could not rename scenario")
}
)
};

$scope.clearMessages = function () {
$scope.messages = [];
};
Expand Down
5 changes: 4 additions & 1 deletion templates/scenarioEditor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
<div class="navbar navbar-default pd-info-bar">
<ul class="nav navbar-nav navbar-left">
<li>
<a href="{{ scenario.jsonUrl }}"><h2 class="pd-info-title">Editing: {{ scenario.name }}</h2></a>
<h2 class="pd-info-title">Editing: </h2>
<input class="input input-md" type="text" ng-model="scenarioName" value="{{ scenario.name }}"/>
<button class="btn btn-primary navbar-btn" ng-click="rename('{{ scenario.id }}')">Re-name</button>
</li>
</ul>
<ul>
<li class="nav navbar-nav navbar-right">
<button class="btn btn-primary navbar-btn" ng-click="save('{{ scenario.id }}')">Save</button>
<button class="btn btn-danger navbar-btn" ng-click="delete('{{ scenario.id }}')">Delete</button>
<a href="{{ scenario.jsonUrl }}" target="_blank">Gitlab</a>
</li>
</ul>
</div>
Expand Down

0 comments on commit 2b04b41

Please sign in to comment.