Skip to main content

start refactoring the actions

ID
19c8508
date
2023-05-13 13:22:37+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
0e1eaa6
message
start refactoring the actions
changed files
2 files, 12 additions, 8 deletions

Changed files

server.py (6041) → server.py (6136)

diff --git a/server.py b/server.py
index b20d042..c40995d 100755
--- a/server.py
+++ b/server.py
@@ -57,11 +57,13 @@ class PhotosData:
 
         return render_template('index.html', assets=all_assets, position=position, prev_five=prev_five, this_asset=this_asset, next_five=next_five)
 
-    def toggle_favorite(self, local_identifier):
-        subprocess.check_call(['swift', 'actions/run_action.swift', local_identifier, 'toggle-favorite'])
+    def run_action(self, local_identifier, action):
+        subprocess.check_call(['swift', 'actions/run_action.swift', local_identifier, action])
 
         this_asset = self.all_assets[self.all_positions[local_identifier]]
-        this_asset['isFavorite'] = not this_asset['isFavorite']
+
+        if action == 'toggle-favorite':
+            this_asset['isFavorite'] = not this_asset['isFavorite']
 
         self.get_response.cache_clear()
 
@@ -191,13 +193,15 @@ def needs_action():
     return _perform_action(request, photos_data.needs_action)
 
 
-@app.route('/actions/toggle_favorite')
-def toggle_favorite():
+@app.route('/actions')
+def run_action():
     local_identifier = request.args['localIdentifier']
+    action = request.args['action']
 
-    photos_data.toggle_favorite(local_identifier)
+    photos_data.run_action(local_identifier, action)
 
-    return redirect(url_for('index', localIdentifier=local_identifier))
+    if action == 'toggle-favorite':
+        return redirect(url_for('index', localIdentifier=local_identifier))
 
 
 @app.route('/image')

templates/index.html (8145) → templates/index.html (8152)

diff --git a/templates/index.html b/templates/index.html
index 348b4dd..895d4ca 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -210,7 +210,7 @@ document.onkeydown = function(e) {
     window.location = "/actions/needs_action?localIdentifier={{ this_asset['localIdentifier'] }}";
   }
   else if (e.key === "f") {
-     window.location = "/actions/toggle_favorite?localIdentifier={{ this_asset['localIdentifier'] }}";
+     window.location = "/actions?localIdentifier={{ this_asset['localIdentifier'] }}&action=toggle-favorite";
    }
 }
 </script>