Skip to content

Commit

Permalink
Merge 04ca15f into 3816783
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Oct 10, 2018
2 parents 3816783 + 04ca15f commit adf896f
Show file tree
Hide file tree
Showing 17 changed files with 476 additions and 261 deletions.
1 change: 1 addition & 0 deletions db/migrate/project/1810082056.add-project-base.sql
@@ -0,0 +1 @@
ALTER TABLE project ADD COLUMN base TEXT;
4 changes: 2 additions & 2 deletions db/schema/project.sql
Expand Up @@ -12,15 +12,15 @@
--

-- Save the current migration number
PRAGMA user_version=1803301510;
PRAGMA user_version=1810082056;

-- Load sqlite3 .dump
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE project (
project_id TEXT NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
created NUMERIC NOT NULL DEFAULT CURRENT_TIMESTAMP,
created NUMERIC NOT NULL DEFAULT CURRENT_TIMESTAMP, base TEXT,

CHECK (project_id != ''),
CHECK (name != '')
Expand Down
11 changes: 6 additions & 5 deletions src/actions/wizard.js
Expand Up @@ -21,12 +21,12 @@ module.exports = {
complete(payload, meta = {}) {
return async () => {
try {
let { file, name } = payload
let { file, name, base } = payload
info(`creating new project ${name} in ${file}`)

if (meta.truncate) await rm(file)

file = await Database.create(file, create, { name })
file = await Database.create(file, create, { name, base })
ipc.send(PROJECT.CREATED, { file })

} catch (error) {
Expand All @@ -49,9 +49,10 @@ module.exports = {
save(payload) {
return async (dispatch) => {
try {
const file = await save.project({ defaultPath: payload })
dispatch(module.exports.project.update({ file }))

let file = await save.project({ defaultPath: payload })
if (file) {
dispatch(module.exports.project.update({ file }))
}
} catch (error) {
fail(error)
}
Expand Down
1 change: 1 addition & 0 deletions src/browser/tropy.js
Expand Up @@ -680,6 +680,7 @@ class Tropy extends EventEmitter {
debug: this.debug,
dev: this.dev,
home: app.getPath('userData'),
user: app.getPath('home'),
documents: app.getPath('documents'),
pictures: app.getPath('pictures'),
cache: this.cache.root,
Expand Down
17 changes: 9 additions & 8 deletions src/commands/item.js
Expand Up @@ -56,10 +56,10 @@ class Import extends ImportCommand {
static get ACTION() { return ITEM.IMPORT }

*exec() {
const { db } = this.options
let { db } = this.options
let { files, list } = this.action.payload

const items = []
let items = []

if (!files) {
this.isInteractive = true
Expand All @@ -70,13 +70,14 @@ class Import extends ImportCommand {

yield put(act.nav.update({ mode: MODE.PROJECT, query: '' }))

const [itemp, ptemp] = yield all([
select(getItemTemplate),
select(getPhotoTemplate)
let [base, itemp, ptemp] = yield select(state => [
state.project.base,
getItemTemplate(state),
getPhotoTemplate(state)
])

const defaultItemData = getTemplateValues(itemp)
const defaultPhotoData = getTemplateValues(ptemp)
let defaultItemData = getTemplateValues(itemp)
let defaultPhotoData = getTemplateValues(ptemp)

for (let i = 0, total = files.length; i < total; ++i) {
let file, image, item, photo
Expand All @@ -92,7 +93,7 @@ class Import extends ImportCommand {
[DC.title]: text(image.title), ...defaultItemData
})

photo = await mod.photo.create(tx, ptemp.id, {
photo = await mod.photo.create(tx, { base, template: ptemp.id }, {
item: item.id, image, data: defaultPhotoData
})

Expand Down
74 changes: 43 additions & 31 deletions src/commands/photo.js
Expand Up @@ -20,17 +20,17 @@ class Consolidate extends ImportCommand {
static get ACTION() { return PHOTO.CONSOLIDATE }

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

const photos = yield select(state =>
blank(payload) ?
values(state.photos) :
pluck(state.photos, payload))
let [project, photos] = yield select(state => [
state.project,
blank(payload) ? values(state.photos) : pluck(state.photos, payload)
])

for (let i = 0, total = photos.length; i < total; ++i) {
const photo = photos[i]
let photo = photos[i]

try {
let { image, hasChanged, error } = yield call(Image.check, photo, meta)
Expand Down Expand Up @@ -63,7 +63,7 @@ class Consolidate extends ImportCommand {

const data = { id: photo.id, ...image.toJSON() }

yield call(mod.photo.save, db, data)
yield call(mod.photo.save, db, data, project)
yield put(act.photo.update({
broken: false,
consolidated: new Date(),
Expand Down Expand Up @@ -104,11 +104,11 @@ class Create extends ImportCommand {
static get ACTION() { return PHOTO.CREATE }

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

const photos = []
let photos = []

if (idx == null) {
idx = [yield select(state => state.items[item].photos.length)]
Expand All @@ -121,8 +121,12 @@ class Create extends ImportCommand {

if (!files) return []

const template = yield select(getPhotoTemplate)
const data = getTemplateValues(template)
let [base, template] = yield select(state => [
state.project.base,
getPhotoTemplate(state)
])

let data = getTemplateValues(template)

for (let i = 0, total = files.length; i < total; ++i) {
let file
Expand All @@ -136,7 +140,7 @@ class Create extends ImportCommand {
yield* this.handleDuplicate(image)

photo = yield call(db.transaction, tx =>
mod.photo.create(tx, template.id, {
mod.photo.create(tx, { base, template: template.id }, {
item, image, data, position: idx[0] + i + 1
}))

Expand Down Expand Up @@ -198,30 +202,35 @@ class Duplicate extends ImportCommand {
static get ACTION() { return PHOTO.DUPLICATE }

*exec() {
const { db } = this.options
const { payload } = this.action
const { item } = payload
let { db } = this.options
let { payload } = this.action
let { item } = payload

assert(!blank(payload.photos), 'missing photos')

const [order, originals, data] = yield select(state => [
let [base, order, originals, data] = yield select(state => [
state.project.base,
state.items[item].photos,
pluck(state.photos, payload.photos),
pluck(state.metadata, payload.photos)
])

const idx = [order.indexOf(payload.photos[0]) + 1]
const total = originals.length
const photos = []
let idx = [order.indexOf(payload.photos[0]) + 1]
let total = originals.length
let photos = []

for (let i = 0; i < total; ++i) {
const { template, path } = originals[i]

try {
const image = yield call(Image.read, path)
let image = yield call(Image.read, path)

const photo = yield call(db.transaction, tx =>
mod.photo.create(tx, template, { item, image, data: data[i] }))
let photo = yield call(db.transaction, tx =>
mod.photo.create(tx, { base, template }, {
item,
image,
data: data[i]
}))

yield put(act.metadata.load([photo.id]))

Expand Down Expand Up @@ -258,9 +267,10 @@ class Load extends Command {
*exec() {
const { db } = this.options
const { payload } = this.action
const { project } = yield select()

const photos = yield call(db.seq, conn =>
mod.photo.load(conn, payload))
mod.photo.load(conn, payload, project))

return photos
}
Expand Down Expand Up @@ -329,17 +339,19 @@ class Save extends Command {
static get ACTION() { return PHOTO.SAVE }

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

const original = yield select(state =>
pick(state.photos[id], keys(data)))
let [original, project] = yield select(state => [
pick(state.photos[id], keys(data)),
state.project.base
])

const params = { id, timestamp: meta.now, ...data }

yield call(db.transaction, async tx => {
await mod.photo.save(tx, params)
await mod.photo.save(tx, params, project)
await mod.image.save(tx, params)
})

Expand Down
29 changes: 20 additions & 9 deletions src/commands/project.js
Expand Up @@ -2,29 +2,40 @@

const { call, put, select } = require('redux-saga/effects')
const { Command } = require('./command')
const actions = require('../actions/project')
const { SAVE } = require('../constants/project')
const { save } = require('../models/project')
const { pick } = require('../common/util')
const act = require('../actions')
const mod = require('../models')


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

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

this.original = (yield select()).project
this.original = yield select(state =>
pick(state.project, Object.keys(payload)))

yield put(actions.update(payload))
yield call(save, db, { id, ...payload })
let doRebase = ('base' in payload && payload.base !== this.original.base)

this.undo = actions.save({ name: this.original.name })
yield put(act.project.update(payload))

yield call(db.transaction, async tx => {
await mod.project.save(tx, { id, ...payload })

if (doRebase) {
await mod.photo.rebase(tx, payload.base, this.original.base)
}
})

this.undo = act.project.save({ name: this.original.name })
}

*abort() {
if (this.original) {
yield put(actions.update({ name: this.original.name }))
yield put(act.project.update(this.original))
}
}
}
Expand Down

0 comments on commit adf896f

Please sign in to comment.