Skip to content

Commit

Permalink
Merge pull request #325 from tropy/feature/templates
Browse files Browse the repository at this point in the history
Templates everywhere
  • Loading branch information
inukshuk committed Feb 13, 2019
2 parents 8df00d9 + 59c0ab9 commit 87887af
Show file tree
Hide file tree
Showing 35 changed files with 712 additions and 404 deletions.
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
}

0 comments on commit 87887af

Please sign in to comment.