wire up the other actions
- ID
d8dcb11- date
2023-05-13 16:57:06+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
2c52306- message
wire up the other actions- changed files
4 files, 229 additions, 203 deletions
Changed files
actions/run_action.swift (2382) → actions/run_action.swift (3505)
diff --git a/actions/run_action.swift b/actions/run_action.swift
index 4a9a4e2..8b71293 100644
--- a/actions/run_action.swift
+++ b/actions/run_action.swift
@@ -64,6 +64,7 @@ let action = arguments[2]
let flagged = getAlbumWith(name: "Flagged")
let rejected = getAlbumWith(name: "Rejected")
let needsAction = getAlbumWith(name: "Needs Action")
+let crossStitch = getAlbumWith(name: "Cross stitch")
let photo = getPhotoWith(uuid: arguments[1])
@@ -76,21 +77,51 @@ try PHPhotoLibrary.shared().performChangesAndWait {
PHAssetCollectionChangeRequest(for: rejected)!
let changeNeedsAction =
PHAssetCollectionChangeRequest(for: needsAction)!
+ let changeCrossStitch =
+ PHAssetCollectionChangeRequest(for: crossStitch)!
let assets = [photo] as NSFastEnumeration
if action == "toggle-favorite" {
changeAsset.isFavorite = !photo.isFavorite
- }
-
- if action == "toggle-flagged" {
+ } else if action == "toggle-flagged" {
changeRejected.removeAssets(assets)
changeNeedsAction.removeAssets(assets)
if (isPhotoInAlbum(photo: photo, collection: flagged)) {
+ changeFlagged.removeAssets(assets)
+ } else {
changeFlagged.addAssets(assets)
+ }
+ } else if action == "toggle-rejected" {
+ changeFlagged.removeAssets(assets)
+ changeNeedsAction.removeAssets(assets)
+
+ if (isPhotoInAlbum(photo: photo, collection: rejected)) {
+ changeRejected.removeAssets(assets)
} else {
- changeFlagged.removeAssets(assets)
+ changeRejected.addAssets(assets)
}
+ } else if action == "toggle-needs-action" {
+ changeFlagged.removeAssets(assets)
+ changeRejected.removeAssets(assets)
+
+ if (isPhotoInAlbum(photo: photo, collection: needsAction)) {
+ changeNeedsAction.removeAssets(assets)
+ } else {
+ changeNeedsAction.addAssets(assets)
+ }
+ } else if action == "toggle-cross-stitch" {
+ print("GO GO GO")
+ print(crossStitch)
+ print(isPhotoInAlbum(photo: photo, collection: crossStitch))
+ if (isPhotoInAlbum(photo: photo, collection: crossStitch)) {
+ changeCrossStitch.removeAssets(assets)
+ } else {
+ changeCrossStitch.addAssets(assets)
+ }
+ } else {
+ fputs("Unrecognised action: \(action)\n", stderr)
+ exit(1)
}
}
server.py (6064) → server.py (6233)
diff --git a/server.py b/server.py
index c035354..b5200cc 100755
--- a/server.py
+++ b/server.py
@@ -2,6 +2,7 @@
import functools
import json
+import os
import subprocess
import sys
@@ -72,57 +73,34 @@ class PhotosData:
this_asset['albums'].remove('Flagged')
except KeyError:
this_asset['albums'].add('Flagged')
+ elif action == 'toggle-rejected':
+ this_asset['albums'].discard('Flagged')
+ this_asset['albums'].discard('Needs Action')
- this_asset['state'] = get_asset_state(this_asset)
-
- self.get_response.cache_clear()
-
- def reject(self, local_identifier):
- subprocess.check_call(['swift', 'scripts/reject.swift', local_identifier])
-
- this_asset = self.all_assets[self.all_positions[local_identifier]]
-
- try:
- this_asset['albums'].remove('Flagged')
- except KeyError:
- pass
-
- try:
- this_asset['albums'].remove('Needs Action')
- except KeyError:
- pass
-
- this_asset['albums'].add('Rejected')
-
- this_asset['state'] = get_asset_state(this_asset)
-
- self.get_response.cache_clear()
-
- def needs_action(self, local_identifier):
- subprocess.check_call(['swift', 'scripts/needs_action.swift', local_identifier])
-
- this_asset = self.all_assets[self.all_positions[local_identifier]]
-
- try:
- this_asset['albums'].remove('Flagged')
- except KeyError:
- pass
+ try:
+ this_asset['albums'].remove('Rejected')
+ except KeyError:
+ this_asset['albums'].add('Rejected')
+ elif action == 'toggle-needs-action':
+ this_asset['albums'].discard('Flagged')
+ this_asset['albums'].discard('Rejected')
- try:
- this_asset['albums'].remove('Rejected')
- except KeyError:
- pass
+ try:
+ this_asset['albums'].remove('Needs Action')
+ except KeyError:
+ this_asset['albums'].add('Needs Action')
+ elif action == 'toggle-cross-stitch':
+ try:
+ this_asset['albums'].remove('Cross stitch')
+ except KeyError:
+ this_asset['albums'].add('Cross stitch')
- this_asset['albums'].add('Needs Action')
this_asset['state'] = get_asset_state(this_asset)
self.get_response.cache_clear()
-
-
-
photos_data = PhotosData()
@@ -139,6 +117,9 @@ def index():
@functools.cache
def get_thumbnail_path(local_identifier):
+ if os.path.exists(f'/tmp/photos-reviewer/{local_identifier[0]}/{local_identifier}_170.jpg'):
+ return f'/tmp/photos-reviewer/{local_identifier[0]}/{local_identifier}_170.jpg'
+
# 85 * 2x
return subprocess.check_output(['swift', 'get_asset_jpeg.swift', local_identifier, '170']).decode('utf8')
@@ -146,12 +127,16 @@ def get_thumbnail_path(local_identifier):
@app.route('/thumbnail')
def thumbnail():
local_identifier = request.args['localIdentifier']
+
thumbnail_path = get_thumbnail_path(local_identifier)
return send_file(thumbnail_path)
@functools.cache
def get_image_path(local_identifier):
+ if os.path.exists(f'/tmp/photos-reviewer/{local_identifier[0]}/{local_identifier}_2048.jpg'):
+ return f'/tmp/photos-reviewer/{local_identifier[0]}/{local_identifier}_2048.jpg'
+
return subprocess.check_output(['swift', 'get_asset_jpeg.swift', local_identifier, '2048']).decode('utf8')
@@ -184,9 +169,9 @@ def run_action():
photos_data.run_action(local_identifier, action)
- if action == 'toggle-favorite':
+ if action in {'toggle-favorite', 'toggle-cross-stitch'} :
return redirect(url_for('index', localIdentifier=local_identifier))
- else:
+ elif action in {'toggle-flagged', 'toggle-rejected', 'toggle-needs-action'}:
position = photos_data.all_positions[local_identifier]
redirect_to = photos_data.all_assets[position - 1]['localIdentifier']
return redirect(url_for('index', localIdentifier=redirect_to))
static/style.css (291) → static/style.css (3027)
diff --git a/static/style.css b/static/style.css
index 2d47fd2..d38000a 100644
--- a/static/style.css
+++ b/static/style.css
@@ -1,3 +1,160 @@
+body {
+ text-align: center;
+ padding: 0;
+ margin: 10px;
+ font-family: -apple-system;
+}
+
+a {
+ text-decoration: none;
+}
+
+#thumbnails {
+ margin-bottom: 1em;
+ height: 85px;
+}
+
+#thumbnails div.thumbnail {
+ display: inline-block;
+ border: 1px solid lightgrey;
+ margin: 1px;
+ width: 65px;
+ height: 65px;
+ padding: 1px;
+ border-radius: 6px;
+}
+
+#thumbnails div.thumbnail img {
+ width: 65px;
+ height: 65px;
+ border-radius: 4px;
+}
+
+#thumbnails div.thumbnail .state {
+ position: absolute;
+ width: 15px;
+ height: 17px;
+ color: white;
+ text-align: left;
+ padding-left: 3px;
+ padding-top: 1px;
+ font-size: 13px;
+ line-height: 16px;
+ border-bottom-right-radius: 18px;
+ margin-left: -3px;
+ margin-top: -3px;
+ font-family: serif;
+ z-index: 10;
+}
+
+#thumbnails div.this_asset div.thumbnail .state {
+ width: 19px;
+ height: 21px;
+ color: white;
+ text-align: left;
+ padding-left: 4px;
+ padding-top: 2px;
+ font-size: 17px;
+ line-height: 16px;
+ border-bottom-right-radius: 18px;
+ margin-left: -3px;
+ margin-top: -3px;
+ font-family: serif;
+}
+
+#thumbnails div.thumbnail.state-Flagged {
+ border-color: green;
+ border-width: 2px;
+ margin: 0;
+}
+
+#thumbnails div.thumbnail.state-Flagged .state {
+ background: green;
+}
+
+#thumbnails div.thumbnail.state-Rejected {
+ border-color: red;
+ border-width: 2px;
+ margin: 0;
+}
+
+#thumbnails div.thumbnail.state-Rejected .state {
+ background: red;
+}
+
+#thumbnails :not(.this_asset) div.thumbnail.state-Rejected img {
+ opacity: 0.5;
+ filter: saturate(0%);
+ z-index: -10;
+}
+
+#thumbnails div.thumbnail.state-Needs-Action {
+ border-color: blue;
+ border-width: 2px;
+ margin: 0;
+}
+
+#thumbnails div.thumbnail.state-Needs-Action .state {
+ background: blue;
+}
+
+#thumbnails div.this_asset {
+ display: inline-block;
+}
+
+#thumbnails div.this_asset div.thumbnail {
+ width: 85px;
+ height: 85px;
+}
+
+#thumbnails div.this_asset div.thumbnail img {
+ width: 85px;
+ height: 85px;
+}
+
+#thumbnails img {
+ object-fit: cover;
+ aspect-ratio: 1 / 1;
+}
+
+#thumbnails .placeholder {
+ width: 65px;
+ height: 65px;
+ display: inline-block;
+ border: 2px solid lightgrey;
+ opacity: 0.5;
+}
+
+.thumbnail_big {
+ width: 85px;
+ height: 85px;
+}
+
+img#big {
+ max-width: calc(100vw - 20px);
+ /* screen height - 85px (thumbnail bar) - 20px (body padding) -1em (margin below thumbnail bar) - 18px (metadata) - 1em (margin below metadata)*/
+ max-height: calc(100vh - 85px - 20px - 1em - 18px - 1em);
+}
+
+#debug {
+ position: absolute;
+ border: 2px solid darkgrey;
+ text-align: right;
+ opacity: 0.25;
+ padding: 5px 10px;
+ border-radius: 10px;
+ background: white;
+ right: 10px;
+ top: 10px;
+ line-height: 1.25em;
+}
+
+#debug:hover {
+ opacity: 1;
+ box-shadow: 0px 0px 3px darkgrey;
+ z-index: 1000;
+}
+
.favorite {
text-align: right;
position: absolute;
templates/index.html (8173) → templates/index.html (5499)
diff --git a/templates/index.html b/templates/index.html
index bb2e54e..06814b6 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -2,157 +2,6 @@
<link rel="stylesheet" href="/static/style.css">
</head>
-<style>
- body {
- text-align: center;
- padding: 0;
- margin: 10px;
- font-family: -apple-system;
-/* background: black;*/
- }
-
- a {
- text-decoration: none;
- }
-
- #thumbnails {
- margin-bottom: 1em;
- height: 85px;
- }
-
- #thumbnails div.thumbnail {
- display: inline-block;
- border: 1px solid lightgrey;
- margin: 1px;
- width: 65px;
- height: 65px;
- padding: 1px;
- }
-
- #thumbnails div.thumbnail img {
- width: 65px;
- height: 65px;
- }
-
- #thumbnails div.thumbnail .state {
- position: absolute;
- width: 15px;
- height: 17px;
- color: white;
- text-align: left;
- padding-left: 3px;
- padding-top: 1px;
- font-size: 13px;
- line-height: 16px;
- border-bottom-right-radius: 18px;
- margin-left: -3px;
- margin-top: -3px;
- font-family: serif;
- }
-
- #thumbnails div.this_asset div.thumbnail .state {
- width: 19px;
- height: 21px;
- color: white;
- text-align: left;
- padding-left: 4px;
- padding-top: 2px;
- font-size: 17px;
- line-height: 16px;
- border-bottom-right-radius: 18px;
- margin-left: -3px;
- margin-top: -3px;
- font-family: serif;
- }
-
- #thumbnails div.thumbnail.state-Flagged {
- border-color: green;
- border-width: 2px;
- margin: 0;
- }
-
- #thumbnails div.thumbnail.state-Flagged .state {
- background: green;
- }
-
- #thumbnails div.thumbnail.state-Rejected {
- border-color: red;
- border-width: 2px;
- margin: 0;
- }
-
- #thumbnails div.thumbnail.state-Rejected .state {
- background: red;
- }
-
- #thumbnails div.thumbnail.state-Needs-Action {
- border-color: blue;
- border-width: 2px;
- margin: 0;
- }
-
- #thumbnails div.thumbnail.state-Needs-Action .state {
- background: blue;
- }
-
- #thumbnails div.this_asset {
- display: inline-block;
- }
-
- #thumbnails div.this_asset div.thumbnail {
- width: 85px;
- height: 85px;
- }
-
- #thumbnails div.this_asset div.thumbnail img {
- width: 85px;
- height: 85px;
- }
-
- #thumbnails img {
- object-fit: cover;
- aspect-ratio: 1 / 1;
- }
-
- #thumbnails .placeholder {
- width: 65px;
- height: 65px;
- display: inline-block;
- border: 2px solid lightgrey;
- opacity: 0.5;
- }
-
- .thumbnail_big {
- width: 85px;
- height: 85px;
- }
-
- img#big {
- max-width: calc(100vw - 20px);
- /* screen height - 85px (thumbnail bar) - 20px (body padding) -1em (margin below thumbnail bar) - 18px (metadata) - 1em (margin below metadata)*/
- max-height: calc(100vh - 85px - 20px - 1em - 18px - 1em);
- }
-
- #debug {
- position: absolute;
- border: 2px solid darkgrey;
- text-align: right;
- opacity: 0.25;
- padding: 5px 10px;
- border-radius: 10px;
- background: white;
- right: 10px;
- top: 10px;
- line-height: 1.25em;
- }
-
- #debug:hover {
- opacity: 1;
- box-shadow: 0px 0px 3px darkgrey;
- z-index: 1000;
- }
-</style>
-
<details id="debug">
<summary>debug</summary>
<strong>this asset:</strong> {{ this_asset['localIdentifier'] }}
@@ -206,14 +55,18 @@ document.onkeydown = function(e) {
if (e.key === "1") {
window.location = "/actions?localIdentifier={{ this_asset['localIdentifier'] }}&action=toggle-flagged";
} else if (e.key === "2") {
- window.location = "/actions/reject?localIdentifier={{ this_asset['localIdentifier'] }}";
+ window.location = "/actions?localIdentifier={{ this_asset['localIdentifier'] }}&action=toggle-rejected";
} else if (e.key === "3") {
- window.location = "/actions/needs_action?localIdentifier={{ this_asset['localIdentifier'] }}";
+ window.location = "/actions?localIdentifier={{ this_asset['localIdentifier'] }}&action=toggle-needs-action";
}
else
if (e.key === "f") {
- window.location = "/actions?localIdentifier={{ this_asset['localIdentifier'] }}&action=toggle-favorite";
- }
+ window.location = "/actions?localIdentifier={{ this_asset['localIdentifier'] }}&action=toggle-favorite";
+ }
+ else
+ if (e.key === "c") {
+ window.location = "/actions?localIdentifier={{ this_asset['localIdentifier'] }}&action=toggle-cross-stitch";
+ }
}
</script>