Skip to content

Commit

Permalink
Allow adding/moving/deleting repo refs (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Dec 6, 2021
1 parent 7a6c5a2 commit 3d1c554
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 41 deletions.
49 changes: 49 additions & 0 deletions src/components/GrampsjsFormRepoRef.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Form for adding a new event reference
*/

import {html} from 'lit'
import '@material/mwc-textfield'
import '@material/mwc-icon-button'
import '@material/mwc-icon'
import '@material/mwc-button'

import './GrampsjsFormSelectType.js'
import './GrampsjsFormSelectObjectList.js'
import './GrampsjsFormString.js'
import {GrampsjsObjectForm} from './GrampsjsObjectForm.js'

class GrampsjsFormRepoRef extends GrampsjsObjectForm {
renderForm () {
return html`
<grampsjs-form-select-object-list
fixedMenuPosition
style="min-height: 300px;"
objectType="repository"
.strings="${this.strings}"
id="repository-select"
label="${this._('Select')}"
class="edit"
></grampsjs-form-select-object-list>
<h4 class="label">${this._('Call Number')}</h4>
<p>
<grampsjs-form-string fullwidth id="call_number" value="${this.data.call_number}"></grampsjs-form-string>
</p>
<grampsjs-form-select-type
required
id="source-media-type"
heading="${this._('Type')}"
.strings="${this.strings}"
typeName="source_media_types"
defaultTypeName="Book"
.types="${this.types}"
.typesLocale="${this.typesLocale}"
>
</grampsjs-form-select-type>
`
}
}

window.customElements.define('grampsjs-form-reporef', GrampsjsFormRepoRef)
10 changes: 8 additions & 2 deletions src/components/GrampsjsObjectForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ export class GrampsjsObjectForm extends GrampsjsTranslateMixin(LitElement) {
this.data = {...this.data, private: e.detail.checked}
}
if ([
'author', 'pubinfo', 'abbrev', 'page', 'desc', 'title', 'description', 'lat', 'long'
'author', 'pubinfo', 'abbrev', 'page', 'desc', 'title', 'description', 'lat', 'long', 'call_number'
].includes(originalTarget.id)) {
this.data = {...this.data, [originalTarget.id]: e.detail.data}
}
if ([
'event-select-list', 'media-select-list', 'child-select-list', 'place-select-list'
'event-select-list', 'media-select-list', 'child-select-list', 'place-select-list', 'repository-select-list'
].includes(originalTarget.id)) {
const [handle] = e.detail.data
if (handle) {
Expand All @@ -208,6 +208,9 @@ export class GrampsjsObjectForm extends GrampsjsTranslateMixin(LitElement) {
if (originalTarget.id === 'event-role-type') {
this.data = {...this.data, role: {_class: 'EventRoleType', string: e.detail.data}}
}
if (originalTarget.id === 'source-media-type') {
this.data = {...this.data, media_type: {_class: 'SourceMediaType', string: e.detail.data}}
}
if (originalTarget.id === 'name-type') {
this.data = {...this.data, type: {_class: 'NameType', string: e.detail.data}}
}
Expand All @@ -217,6 +220,9 @@ export class GrampsjsObjectForm extends GrampsjsTranslateMixin(LitElement) {
if (originalTarget.id === 'child-mrel') {
this.data = {...this.data, mrel: {_class: 'ChildRefType', string: e.detail.data}}
}
if (originalTarget.id === 'child-mrel') {
this.data = {...this.data, mrel: {_class: 'ChildRefType', string: e.detail.data}}
}
if (originalTarget.id === 'note-select-list') {
this.data = e.detail
}
Expand Down
83 changes: 44 additions & 39 deletions src/components/GrampsjsRepositories.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {html} from 'lit'

import {GrampsjsEditableTable} from './GrampsjsEditableTable.js'
import './GrampsjsFormSelectObject.js'
import './GrampsjsObjectForm.js'
import './GrampsjsFormRepoRef.js'
import {fireEvent} from '../util.js'

export class GrampsjsRepositories extends GrampsjsEditableTable {
Expand All @@ -15,8 +15,8 @@ export class GrampsjsRepositories extends GrampsjsEditableTable {
constructor () {
super()
this.extended = []
this.objType = 'Event'
this._columns = ['Title', 'Call Number', 'Media Type', '']
this.objType = 'Repository'
this._columns = ['Title', 'Call Number', '_Media Type:', '']
this.dialogContent = ''
}

Expand All @@ -25,50 +25,55 @@ export class GrampsjsRepositories extends GrampsjsEditableTable {
<tr @click=${() => this._handleClick(this.extended[i].gramps_id)}>
<td>${this.extended[i].name}</td>
<td>${obj.call_number}</td>
<td>${obj.media_type}</td>
<td></td>
<td>${this._(obj.media_type)}</td>
<td>${this.edit
? this._renderActionBtns(obj.ref, i === 0, i === arr.length - 1)
: ''}
</td>
</tr>
`
}

// renderAfterTable () {
// return this.edit
// ? html`
// <mwc-icon-button
// class="edit large"
// icon="add_circle"
// @click="${this._handleAddClick}"
// ></mwc-icon-button>
// ${this.dialogContent}
// `
// : ''
// }
renderAfterTable () {
return this.edit
? html`
<mwc-icon-button
class="edit large"
icon="add_circle"
@click="${this._handleAddClick}"
></mwc-icon-button>
${this.dialogContent}
`
: ''
}

// _handleAddClick () {
// this.dialogContent = html`
// <grampsjs-form-eventref
// new
// @object:save="${this._handleEventRefSave}"
// @object:cancel="${this._handleEventRefCancel}"
// .strings="${this.strings}"
// objType="${this.objType}"
// dialogTitle = ${this._('Share an existing event')}
// >
// </grampsjs-form-eventref>
// `
// }
_handleAddClick () {
this.dialogContent = html`
<grampsjs-form-reporef
new
@object:save="${this._handleRepoRefAdd}"
@object:cancel="${this._handleRepoRefCancel}"
.strings="${this.strings}"
objType="${this.objType}"
dialogTitle = ${this._('Add an existing repository')}
>
</grampsjs-form-reporef>
`
}

// _handleEventRefSave (e) {
// fireEvent(this, 'edit:action', {action: 'addEventRef', data: e.detail.data})
// e.preventDefault()
// e.stopPropagation()
// this.dialogContent = ''
// }
_handleRepoRefAdd (e) {
if (e.detail.data.ref) {
fireEvent(this, 'edit:action', {action: 'addRepoRef', data: e.detail.data})
}
e.preventDefault()
e.stopPropagation()
this.dialogContent = ''
}

// _handleEventRefCancel () {
// this.dialogContent = ''
// }
_handleRepoRefCancel () {
this.dialogContent = ''
}

_handleClick (grampsId) {
if (!this.edit) {
Expand Down
4 changes: 4 additions & 0 deletions src/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const grampsStrings = [
'Abort changes?',
'About',
'Add an existing person as a child of the family',
'Add an existing repository',
'Add',
'Address Note',
'Addresses',
Expand All @@ -58,10 +59,12 @@ export const grampsStrings = [
'Birth Name',
'Birth Place',
'Birth',
'Book',
'Borough',
'Building',
'Calculated',
'Call name',
'Call Number',
'Cancel',
'Child Reference Note',
'Children',
Expand Down Expand Up @@ -145,6 +148,7 @@ export const grampsStrings = [
'Media Object',
'Media Objects',
'Media Reference Note',
'_Media Type:',
'Media',
'Military Service',
'Mother',
Expand Down
8 changes: 8 additions & 0 deletions src/views/GrampsjsViewObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ export class GrampsjsViewObject extends GrampsjsView {
})
} else if (e.detail.action === 'addCitation') {
this.addHandle(e.detail.data.data[0], this._data, this._className, 'citation_list')
} else if (e.detail.action === 'delRepository') {
this.delObject(e.detail.handle, this._data, this._className, 'reporef_list')
} else if (e.detail.action === 'addRepoRef') {
this.addObject(e.detail.data, this._data, this._className, 'reporef_list')
} else if (e.detail.action === 'upRepository') {
this.moveObject(e.detail.handle, this._data, this._className, 'reporef_list', 'up')
} else if (e.detail.action === 'downRepository') {
this.moveObject(e.detail.handle, this._data, this._className, 'reporef_list', 'down')
} else if (e.detail.action === 'addMediaRef') {
this.addObject(e.detail.data, this._data, this._className, 'media_list')
} else if (e.detail.action === 'updateMediaRef') {
Expand Down

0 comments on commit 3d1c554

Please sign in to comment.