Skip to content

Commit

Permalink
Generic-UI-list-editor: Implemented generic UI list editor, changed i…
Browse files Browse the repository at this point in the history
…nstances of labels, keywords and people in image to generic component
  • Loading branch information
adrielulanovsky committed Nov 26, 2021
1 parent 76a85af commit e3e4c13
Show file tree
Hide file tree
Showing 19 changed files with 409 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@
</span>
</dd>

<dt ng-if="ctrl.singleImage && (ctrl.rawMetadata.peopleInImage || ctrl.userCanEdit)" class="image-info__wrap metadata-line metadata-line__key image-info__group--dl__key--panel">People</dt>
<dd ng-if="ctrl.singleImage && (ctrl.rawMetadata.peopleInImage || ctrl.userCanEdit)" class="image-info__wrap metadata-line metadata-line__info image-info__group--dl__value--panel">
<dt ng-if="(ctrl.rawMetadata.peopleInImage || ctrl.userCanEdit)" class="image-info__wrap metadata-line metadata-line__key image-info__group--dl__key--panel">People</dt>
<dd ng-if="(ctrl.rawMetadata.peopleInImage || ctrl.userCanEdit)" class="image-info__wrap metadata-line metadata-line__info image-info__group--dl__value--panel">
<button data-cy="it-edit-people-button"
class="image-info__edit"
ng-if="ctrl.userCanEdit"
Expand All @@ -375,14 +375,15 @@
'image-info__editor--saving': peopleInImageEditForm.$waiting,
'text-input': true}">

<span class="metadata-line__info">
<span ng:repeat="person in ctrl.metadata.peopleInImage">
<a ui:sref="search.results({query: (person | queryFilter:'person')})">{{person}}</a>
<span ng-if="ctrl.metadata.peopleInImage.length > 1 && $index != ctrl.metadata.peopleInImage.length - 1"></span>
</span>

<span class="editable-empty" ng-if="!ctrl.metadata.peopleInImage && ctrl.userCanEdit">Unknown (click ✎ to add)</span>
</span>
<span class="editable-empty" ng-if="!ctrl.metadata.peopleInImage && ctrl.userCanEdit">Unknown (click ✎ to add)</span>
<ui-list-editor-info-panel
images="ctrl.selectedImages"
add-to-images="ctrl.addPersonToImages"
remove-from-images="ctrl.removePersonFromImages"
accessor="ctrl.peopleAccessor"
query-filter="queryFilter:'person'"
element-name="person">
</ui-list-editor-info-panel>
</span>
</dd>
</dl>
Expand Down Expand Up @@ -597,22 +598,14 @@
</gr-add-label>
</dt>
<dd class="labels">
<li class="label"
ng-repeat="label in ctrl.selectedLabels | orderBy:'data'"
ng-class="{'label--partial': label.count < ctrl.selectedImages.size}">
<button ng-if="label.count < ctrl.selectedImages.size"
class="label__add"
title="Apply label to all"
ng-click="ctrl.addLabel(label.data)">
<gr-icon>library_add</gr-icon>
</button>
<span class="label__value">{{label.data}}</span>
<button class="label__remove"
title="Remove label from all"
ng-click="ctrl.removeLabel(label.data)">
<gr-icon>close</gr-icon>
</button>
</li>
<ui-list-editor-info-panel
images="ctrl.selectedImages"
add-to-images="ctrl.addLabelToImages"
remove-from-images="ctrl.removeLabelFromImages"
accessor="ctrl.labelAccessor"
query-filter="queryLabelFilter"
element-name="label">
</ui-list-editor-info-panel>
</dd>
</dl>
</div>
Expand Down Expand Up @@ -642,12 +635,11 @@
<dt class="image-info__heading image-info__wrap">Keywords</dt>
<dd class="image-info__keywords">
<ul>
<li class="image-info__keyword"
ng-repeat="keyword in ctrl.metadata.keywords track by $index">
<a ui-sref="search.results({query: (keyword | queryFilter:'keyword')})">
{{keyword}}
</a>
</li>
<ui-list-editor-compact
images="ctrl.selectedImages"
accessor="ctrl.keywordAccessor"
query-filter="queryFilter:'keyword'">
</ui-list-editor-compact>
</ul>
</dd>
</dl>
Expand Down
40 changes: 32 additions & 8 deletions kahuna/public/js/components/gr-image-metadata/gr-image-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import template from './gr-image-metadata.html';
import '../../image/service';
import '../../edits/service';
import '../gr-description-warning/gr-description-warning';
import { editOptions, overwrite } from '../../util/constants/editOptions';
import '../../util/storage';
import { editOptions, overwrite } from '../../util/constants/editOptions';
import '../../services/image-accessor';
import '../../services/image-list';
import '../../services/label';
Expand Down Expand Up @@ -146,16 +146,40 @@ module.controller('grImageMetadataCtrl', [
});
};

ctrl.addLabel = function (label) {
var imageArray = Array.from(ctrl.selectedImages);
labelService.batchAdd(imageArray, [label]);
ctrl.addLabelToImages = labelService.batchAdd;
ctrl.removeLabelFromImages = labelService.batchRemove;
ctrl.labelAccessor = (image) => imageAccessor.readLabels(image).map(label => label.data);

ctrl.peopleAccessor = (image) => imageAccessor.readPeopleInImage(image);
ctrl.removePersonFromImages = (images, removedPerson) => {
images.map((image) => {
const maybeNewPeopleInImage = ctrl.peopleAccessor(image)?.filter((person) => person !== removedPerson);
const newPeopleInImage = maybeNewPeopleInImage ? maybeNewPeopleInImage : [];
editsService.batchUpdateMetadataField(
[image],
'peopleInImage',
newPeopleInImage,
ctrl.descriptionOption
);
});
return Promise.resolve(ctrl.selectedImages);
};

ctrl.removeLabel = function (label) {
var imageArray = Array.from(ctrl.selectedImages);
labelService.batchRemove(imageArray, label);
ctrl.addPersonToImages = (images, addedPerson) => {
images.map((image) => {
const currentPeopleInImage = ctrl.peopleAccessor(image);
const newPeopleInImage = currentPeopleInImage ? [...currentPeopleInImage, addedPerson] : [addedPerson];
editsService.batchUpdateMetadataField(
[image],
'peopleInImage',
newPeopleInImage,
ctrl.descriptionOption
);
});
return Promise.resolve(ctrl.selectedImages);
};

ctrl.keywordAccessor = (image) => imageAccessor.readMetadata(image).keywords;

const ignoredMetadata = [
'title', 'description', 'copyright', 'keywords', 'byline',
'credit', 'subLocation', 'city', 'state', 'country',
Expand Down
14 changes: 10 additions & 4 deletions kahuna/public/js/edits/image-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,16 @@ <h1>Organisation and Grouping</h1>
active="ctrl.inputtingLabel"
class="result-editor__field-container__add-button">
</gr-add-label>
<ui-labeller
image="ctrl.image"
with-batch="ctrl.withBatch">
</ui-labeller>
<ui-list-editor-upload
images="ctrl.imageAsArray"
with-batch="ctrl.withBatch"
add-to-images="ctrl.addLabelToImages"
remove-from-images="ctrl.removeLabelFromImages"
accessor="ctrl.labelAccessor"
query-filter="queryLabelFilter"
element-name="label"
element-name-plural="labels">
</ui-list-editor-upload>
</div>
</div>

Expand Down
16 changes: 15 additions & 1 deletion kahuna/public/js/edits/image-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import './image-editor.css';

import {service} from './service';
import {imageService} from '../image/service';
import '../services/label';
import {imageAccessor} from '../services/image-accessor';
import {usageRightsEditor} from '../usage-rights/usage-rights-editor';
import {leases} from '../leases/leases';
import {archiver} from '../components/gr-archiver-status/gr-archiver-status';
import {collectionsApi} from '../services/api/collections-api';
import {rememberScrollTop} from '../directives/gr-remember-scroll-top';


export var imageEditor = angular.module('kahuna.edits.imageEditor', [
service.name,
imageService.name,
"kahuna.services.label",
imageAccessor.name,
usageRightsEditor.name,
archiver.name,
collectionsApi.name,
Expand All @@ -28,6 +31,8 @@ imageEditor.controller('ImageEditorCtrl', [
'editsService',
'editsApi',
'imageService',
'labelService',
'imageAccessor',
'collections',
'mediaApi',

Expand All @@ -37,6 +42,8 @@ imageEditor.controller('ImageEditorCtrl', [
editsService,
editsApi,
imageService,
labelService,
imageAccessor,
collections,
mediaApi) {

Expand Down Expand Up @@ -67,6 +74,12 @@ imageEditor.controller('ImageEditorCtrl', [

ctrl.undelete = undelete;

ctrl.imageAsArray = [ctrl.image];

ctrl.addLabelToImages = labelService.batchAdd;
ctrl.removeLabelFromImages = labelService.batchRemove;
ctrl.labelAccessor = (image) => imageAccessor.readLabels(image).map(label => label.data);

//TODO put collections in their own directive
ctrl.addCollection = false;
ctrl.addToCollection = addToCollection;
Expand Down Expand Up @@ -135,6 +148,7 @@ imageEditor.controller('ImageEditorCtrl', [
function onSave() {
return ctrl.image.get().then(newImage => {
ctrl.image = newImage;
ctrl.imageAsArray = [newImage];
ctrl.usageRights = imageService(ctrl.image).usageRights;
updateUsageRightsCategory();
ctrl.status = ctrl.image.data.valid ? 'ready' : 'invalid';
Expand Down
4 changes: 2 additions & 2 deletions kahuna/public/js/edits/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import angular from 'angular';

import './labeller';
import './list-editor';

export var edits = angular.module('kahuna.edits', [
'kahuna.edits.labeller'
'kahuna.edits.listEditor'
]);
16 changes: 0 additions & 16 deletions kahuna/public/js/edits/labeller-compact.html

This file was deleted.

33 changes: 0 additions & 33 deletions kahuna/public/js/edits/labeller.html

This file was deleted.

Loading

0 comments on commit e3e4c13

Please sign in to comment.