From 049c2a137368b4c729097e895b88610889cd24a9 Mon Sep 17 00:00:00 2001 From: Vivek Anand Date: Mar 15 2017 13:46:16 +0000 Subject: watch: add reset button for watch feature Signed-off-by: Vivek Anand --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index b4aad6d..0c555f7 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -3485,6 +3485,14 @@ def update_watch_status(session, project, user, watch): ) ).first() + if watch == '-1': + if not watcher: + return 'Watch status is already reset' + + session.delete(watcher) + session.flush() + return 'Watch status reset' + if not watcher: watcher = model.Watcher( project_id=project.id, diff --git a/pagure/templates/repo_master.html b/pagure/templates/repo_master.html index 0a0f0bd..4a1580c 100644 --- a/pagure/templates/repo_master.html +++ b/pagure/templates/repo_master.html @@ -90,13 +90,14 @@ repo.user.user if repo.is_fork else None, repo.namespace) %} - Stop watching {{ + Unwatch {{ repo.name }} {% else %} Watch {{ repo.name }} {% endif -%} - + Reset Watch Status {{ + repo.name }} {{ forkbuttonform.csrf_token }} @@ -305,10 +306,14 @@ $(document).ready(function() { $(".watch-menu a").click(function(){ var selectedValue = $(this).attr('id'); var action = $("#watch_project").attr('action'); - if (selectedValue != "unwatch_button") { + if (selectedValue === "watch_button") { action = action.replace('/settings/0', '/settings/1'); $('#watch_project').attr('action', action); + } else if (selectedValue === "reset_button") { + action = action.replace('/settings/0', '/settings/-1'); + $('#watch_project').attr('action', action); } + $('#watch_project').submit(); }); diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index f2bb386..46f9e3e 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -2342,7 +2342,7 @@ def watch_repo(repo, watch, username=None, namespace=None): if not form.validate_on_submit(): flask.abort(400) - if str(watch) not in ['0', '1']: + if str(watch) not in ['0', '1', '-1']: flask.abort(400) try: