Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templates everywhere #325

Merged
merged 28 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f916788
Add template selectors at each level
inukshuk Feb 8, 2019
8958b3d
Enable selection template creation
inukshuk Feb 8, 2019
086cb63
Add default photo/selection template pref
inukshuk Feb 8, 2019
8c2f12e
Add SaveCommand for saving subject template
inukshuk Feb 11, 2019
0cdde8e
Add error strings
inukshuk Feb 11, 2019
748b7c4
Export subject model helpers
inukshuk Feb 12, 2019
9471324
Update template constants
inukshuk Feb 12, 2019
d5a0f1e
Update template constants
inukshuk Feb 12, 2019
cb1be5d
Add and connect template change actions
inukshuk Feb 12, 2019
64c374c
Add optional icon to template selector
inukshuk Feb 12, 2019
64e0721
Use fragment instead of array
inukshuk Feb 12, 2019
b5c3acf
Use has-icon class instead of icon class on template-select.
flachware Feb 12, 2019
a61ace7
Add space between multiple selects in one form-group.
flachware Feb 12, 2019
0de362d
Wrap template selector icon in .truncate
inukshuk Feb 12, 2019
c39638e
Clean-up TemplateFieldList component
inukshuk Feb 12, 2019
112d432
Lint
inukshuk Feb 12, 2019
8cee582
Lint cont'd
inukshuk Feb 12, 2019
23fde53
Add icons to template-selects.
flachware Feb 12, 2019
719f06f
Move icon prop to Select
inukshuk Feb 12, 2019
1748cd1
Fix capitalization
inukshuk Feb 12, 2019
70d5940
Clean-up TemplateEditor
inukshuk Feb 12, 2019
88e11d2
Style select and popup with icon.
flachware Feb 12, 2019
7ea0804
Just the best words...
inukshuk Feb 12, 2019
73e31eb
Add item.template column
inukshuk Feb 12, 2019
11c86c4
Support sort by item template
inukshuk Feb 12, 2019
c357a0e
Update German strings
inukshuk Feb 12, 2019
b8d1e82
Fix template editor update
inukshuk Feb 12, 2019
59c0ab9
Refactor TemplateEditor
inukshuk Feb 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions res/strings/renderer.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ de:

other {# Objekte}}
selection: Ausschnitt
popup:
placeholder: Neues Feld …
tags:
tab: Tags
add: >
Expand Down Expand Up @@ -227,6 +229,9 @@ de:
saturation:
label: Sättigung
value: "{value, number}"
sharpen:
label: Schärfe
value: "{value, number}"
notepad:
placeholder: Notizen hier eintragen …
completions:
Expand Down
17 changes: 15 additions & 2 deletions res/strings/renderer.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ en:
en: English
fr: Français
ja: 日本語
template: Default Template
templates:
label: Default templates
item: Item
photo: Photo
selection: Selection
debug: Enable Developer Mode
localtime: Assume photo metadata use local timezone
dup:
Expand Down Expand Up @@ -166,6 +170,7 @@ en:
item:
created: Date Added
modified: Modified
template: Template
photo:
file: File
size: Size
Expand Down Expand Up @@ -222,7 +227,7 @@ en:
types:
"https://tropy.org/v1/tropy#Item": Item Template
"https://tropy.org/v1/tropy#Photo": Photo Template
"https://tropy.org/v1/tropy#Selection": Photo Selection Template
"https://tropy.org/v1/tropy#Selection": Selection Template
field:
property: Property
label: Label
Expand Down Expand Up @@ -467,6 +472,8 @@ en:
tag:
save: Failed to save tag.
create: Failed to tag item. Tags must be unique per item.
template:
change: Failed to change item template.
list:
load: Failed to load lists.
create: Failed to create list. List names must be unique.
Expand All @@ -478,6 +485,12 @@ en:
consolidate: Failed to consolidate photos.
create: Failed to import photo.
save: Failed to save photo.
template:
change: Failed to change photo template.
selection:
create: Failed to create photo selection.
template:
change: Failed to change selection template.
ontology:
import: Failed to import vocabulary.
vocab:
Expand Down
26 changes: 18 additions & 8 deletions src/actions/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@ module.exports = {
}
},

save({ id, property, value }, meta) {
return {
type: ITEM.SAVE,
payload: { id: array(id), property, value },
meta: { cmd: 'project', history: 'add', ...meta }
}
},

update(payload, meta) {
return {
type: ITEM.UPDATE,
Expand Down Expand Up @@ -251,5 +243,23 @@ module.exports = {
meta: { ...meta }
}
}
},

template: {
change({ id, template }, meta) {
return {
type: ITEM.TEMPLATE.CHANGE,
payload: {
id: array(id),
property: 'template',
value: template
},
meta: {
cmd: 'project',
history: 'add',
...meta
}
}
}
}
}
18 changes: 18 additions & 0 deletions src/actions/photo.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,23 @@ module.exports = {
meta: { ...meta }
}
}
},

template: {
change({ id, template }, meta) {
return {
type: PHOTO.TEMPLATE.CHANGE,
payload: {
id: array(id),
property: 'template',
value: template
},
meta: {
cmd: 'project',
history: 'add',
...meta
}
}
}
}
}
29 changes: 29 additions & 0 deletions src/actions/selection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const { SELECTION } = require('../constants')
const { array } = require('../common/util')

module.exports = {
create(payload, meta) {
Expand Down Expand Up @@ -80,4 +81,32 @@ module.exports = {
}
},

bulk: {
update(payload, meta = {}) {
return {
type: SELECTION.BULK.UPDATE,
payload,
meta
}
}
},


template: {
change({ id, template }, meta) {
return {
type: SELECTION.TEMPLATE.CHANGE,
payload: {
id: array(id),
property: 'template',
value: template
},
meta: {
cmd: 'project',
history: 'add',
...meta
}
}
}
}
}
79 changes: 5 additions & 74 deletions src/commands/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { DuplicateError } = require('../common/error')
const { all, call, put, select, cps } = require('redux-saga/effects')
const { Command } = require('./command')
const { ImportCommand } = require('./import')
const { SaveCommand } = require('./subject')
const { prompt, open, fail, save } = require('../dialog')
const { Image } = require('../image')
const act = require('../actions')
Expand All @@ -16,7 +17,6 @@ const { darwin } = require('../common/os')
const { ITEM, DC } = require('../constants')
const { MODE } = require('../constants/project')
const { keys } = Object
const { isArray } = Array
const { writeFile: write } = require('fs')
const { win } = require('../window')
const { groupedByTemplate } = require('../export')
Expand Down Expand Up @@ -230,78 +230,9 @@ class Restore extends Command {
}
}

class Save extends Command {
static get ACTION() { return ITEM.SAVE }

*exec() {
const { db } = this.options
const { payload, meta } = this.action

if (!isArray(payload)) {
const { id: ids, property, value } = this.action.payload

assert.equal(property, 'template')

const state = yield select(({ items, ontology, metadata }) => ({
items, templates: ontology.template, metadata
}))

const props = { [property]: value, modified: new Date(meta.now) }
const template = state.templates[value]

assert(template != null, 'unknown template')

const data = getTemplateValues(template)
const datakeys = data != null ? keys(data) : []
const hasData = datakeys.length > 0

const original = ids.map(id => [
id,
get(state.items, [id, property]),
hasData ? pick(state.metadata[id], datakeys, {}, true) : null
])

yield call(db.transaction, async tx => {
await mod.item.update(tx, ids, props, meta.now)

if (hasData) {
await mod.metadata.update(tx, { id: ids, data })
}
})

yield put(act.item.bulk.update([ids, props]))

if (hasData) {
yield put(act.metadata.update({ ids, data }))
}

this.undo = { ...this.action, payload: original }

} else {

let hasData = false
let changed = { props: {}, data: {} }

yield call(db.transaction, async tx => {
for (let [id, template, data] of payload) {
changed.props[id] = { template, modified: new Date(meta.now) }
await mod.item.update(tx, [id], changed.props[id], meta.now)

if (data) {
hasData = true
changed.data[id] = data
await mod.metadata.update(tx, { id, data })
}
}
})

yield put(act.item.bulk.update(changed.props))

if (hasData) {
yield put(act.metadata.merge(changed.data))
}
}
}
class TemplateChange extends SaveCommand {
static get ACTION() { return ITEM.TEMPLATE.CHANGE }
get type() { return 'item' }
}

class Merge extends Command {
Expand Down Expand Up @@ -614,7 +545,7 @@ module.exports = {
Merge,
Split,
Restore,
Save,
TemplateChange,
Preview,
AddTag,
RemoveTag,
Expand Down
10 changes: 9 additions & 1 deletion src/commands/photo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const assert = require('assert')
const { all, call, put, select } = require('redux-saga/effects')
const { Command } = require('./command')
const { ImportCommand } = require('./import')
const { SaveCommand } = require('./subject')
const { fail, open } = require('../dialog')
const mod = require('../models')
const act = require('../actions')
Expand Down Expand Up @@ -404,6 +405,12 @@ class Restore extends Command {
}
}

class TemplateChange extends SaveCommand {
static get ACTION() { return PHOTO.TEMPLATE.CHANGE }
get type() { return 'photo' }
}


module.exports = {
Consolidate,
Create,
Expand All @@ -413,5 +420,6 @@ module.exports = {
Move,
Order,
Restore,
Save
Save,
TemplateChange
}
39 changes: 31 additions & 8 deletions src/commands/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
const { call, put, select } = require('redux-saga/effects')
const { Command } = require('./command')
const { ImportCommand } = require('./import')
const { SaveCommand } = require('./subject')
const { Image } = require('../image')
const mod = require('../models')
const act = require('../actions')
const { SELECTION } = require('../constants')
const { pick, splice } = require('../common/util')
const { keys } = Object

const {
getSelectionTemplate,
getTemplateValues
} = require('../selectors')


class Create extends ImportCommand {
static get ACTION() { return SELECTION.CREATE }
Expand All @@ -18,21 +24,31 @@ class Create extends ImportCommand {
let { db } = this.options
let { payload, meta } = this.action

let photo = yield select(state => state.photos[payload.photo])
let [photo, template] = yield select(state => ([
state.photos[payload.photo],
getSelectionTemplate(state)
]))

let image = yield call(Image.open, photo.path, photo.page)
let idx = (meta.idx != null) ? meta.idx : [photo.selections.length]

let selection = yield call(db.transaction, tx =>
mod.selection.create(tx, null, payload))
let data = getTemplateValues(template)

let data = { selections: [selection.id] }
let selection = yield call(db.transaction, tx =>
mod.selection.create(tx, {
data,
template: template.id,
...payload
}))

yield* this.createThumbnails(selection.id, image, { selection })

yield put(act.photo.selections.add({ id: photo.id, ...data }, { idx }))
let common = { selections: [selection.id] }

this.undo = act.selection.delete({ photo: photo.id, ...data }, { idx })
this.redo = act.selection.restore({ photo: photo.id, ...data }, { idx })
yield put(act.photo.selections.add({ id: photo.id, ...common }, { idx }))

this.undo = act.selection.delete({ photo: photo.id, ...common }, { idx })
this.redo = act.selection.restore({ photo: photo.id, ...common }, { idx })

return selection
}
Expand Down Expand Up @@ -140,12 +156,19 @@ class Save extends Command {
}
}

class TemplateChange extends SaveCommand {
static get ACTION() { return SELECTION.TEMPLATE.CHANGE }
get type() { return 'selection' }
}



module.exports = {
Create,
Delete,
Load,
Order,
Restore,
Save
Save,
TemplateChange
}
Loading