Skip to content

Commit

Permalink
merge master to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shuntian committed Feb 17, 2025
2 parents df2d8de + e85866b commit 2116209
Show file tree
Hide file tree
Showing 39 changed files with 343 additions and 138 deletions.
79 changes: 40 additions & 39 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 27 additions & 30 deletions frontend/src/components/toolbar/single-dropdown-toolbar.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { Fragment } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';

import '../../css/single-dropdown-toolbar.css';

const propTypes = {
withPlusIcon: PropTypes.bool,
opList: PropTypes.array.isRequired
};

Expand Down Expand Up @@ -37,36 +38,32 @@ class SingleDropdownToolbar extends React.Component {
const { opList, withPlusIcon = false } = this.props;

return (
<Fragment>
<Dropdown isOpen={this.state.isDropdownMenuOpen} toggle={this.toggleDropdownMenu}>
<DropdownToggle
tag="span"
role="button"
className={withPlusIcon ? 'ml-2 sf-dropdown-combined-toggle' : 'ml-1 sf-dropdown-toggle'}
onClick={this.toggleDropdownMenu}
onKeyDown={this.onDropdownToggleKeyDown}
data-toggle="dropdown"
>
{withPlusIcon
? (<><i className="sf3-font-new sf3-font main-icon"></i><i className="sf3-font-down sf3-font"></i></>)
: <i className="sf3-font-down sf3-font"></i>
<Dropdown isOpen={this.state.isDropdownMenuOpen} toggle={this.toggleDropdownMenu} direction="down">
<DropdownToggle
tag="span"
role="button"
className={withPlusIcon ? 'ml-2 sf-dropdown-combined-toggle' : 'ml-1 sf-dropdown-toggle'}
onClick={this.toggleDropdownMenu}
onKeyDown={this.onDropdownToggleKeyDown}
data-toggle="dropdown"
>
{withPlusIcon && <i className="sf3-font-new sf3-font main-icon"></i>}
<i className="sf3-font-down sf3-font"></i>
</DropdownToggle>
<DropdownMenu positionFixed={true}>
{opList.map((item, index) => {
if (item == 'Divider') {
return <DropdownItem key={index} divider />;
} else {
return (
<DropdownItem key={index} onClick={item.onClick} onKeyDown={this.onMenuItemKeyDown.bind(this, item)}>
{item.text}
</DropdownItem>
);
}
</DropdownToggle>
<DropdownMenu>
{opList.map((item, index) => {
if (item == 'Divider') {
return <DropdownItem key={index} divider />;
} else {
return (
<DropdownItem key={index} onClick={item.onClick} onKeyDown={this.onMenuItemKeyDown.bind(this, item)}>
{item.text}
</DropdownItem>
);
}
})}
</DropdownMenu>
</Dropdown>
</Fragment>
})}
</DropdownMenu>
</Dropdown>
);
}
}
Expand Down
6 changes: 0 additions & 6 deletions frontend/src/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,6 @@ img[src=""],img:not([src]) { /* for first loading img*/
color: #444;
}

.path-container .add-wiki-dropdown .sf3-font-down {
color: #999;
cursor: pointer;
font-size: 12px;
}

.dir-tool>div {
margin-left: 8px;
}
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/metadata/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ class MetadataManagerAPI {
return this.req.post(url, params);
};

setPeoplePhoto = (repoID, peopleId, recordId) => {
const url = this.server + '/api/v2.1/repos/' + repoID + '/metadata/people-cover-photo/' + peopleId + '/';
const params = {
record_id: recordId
};
return this.req.put(url, params);
};

// ocr
openOCR = (repoID) => {
const url = this.server + '/api/v2.1/repos/' + repoID + '/metadata/ocr/';
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/metadata/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ class Context {
return viewId === FACE_RECOGNITION_VIEW_ID;
};

canSetPeoplePhoto = () => {
const viewId = this.getSetting('viewID');
if (this.permission === 'r' || viewId !== FACE_RECOGNITION_VIEW_ID) {
return false;
}
return true;
};

restoreRows = () => {
// todo
};
Expand Down Expand Up @@ -282,6 +290,11 @@ class Context {
return this.metadataAPI.removePeoplePhotos(repoID, recordId, photoIds);
};

setPeoplePhoto = (recordId, photoId) => {
const repoID = this.settings['repoID'];
return this.metadataAPI.setPeoplePhoto(repoID, recordId, photoId);
};

// file tag
updateFileTags = (data) => {
const repoID = this.settings['repoID'];
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/metadata/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,14 @@ class Store {
this.applyOperation(operation);
};

setPeoplePhoto = (peopleId, selectedPhoto) => {
const type = OPERATION_TYPE.SET_PEOPLE_COVER_PHOTO;
const operation = this.createOperation({
type, repo_id: this.repoId, people_id: peopleId, selected_photo: selectedPhoto
});
this.applyOperation(operation);
};

// tag
updateFileTags = (data) => {
const type = OPERATION_TYPE.UPDATE_FILE_TAGS;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/metadata/store/operations/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const OPERATION_TYPE = {
DELETE_PEOPLE_PHOTOS: 'delete_people_photos',
REMOVE_PEOPLE_PHOTOS: 'remove_people_photos',
ADD_PEOPLE_PHOTOS: 'add_people_photos',
SET_PEOPLE_COVER_PHOTO: 'set_people_cover_photo',

// tag
UPDATE_FILE_TAGS: 'update_file_tags',
Expand Down Expand Up @@ -72,6 +73,7 @@ export const OPERATION_ATTRIBUTES = {
[OPERATION_TYPE.DELETE_PEOPLE_PHOTOS]: ['repo_id', 'people_id', 'deleted_photos'],
[OPERATION_TYPE.REMOVE_PEOPLE_PHOTOS]: ['repo_id', 'people_id', 'removed_photos', 'success_callback'],
[OPERATION_TYPE.ADD_PEOPLE_PHOTOS]: ['repo_id', 'people_id', 'old_people_id', 'added_photos', 'success_callback'],
[OPERATION_TYPE.SET_PEOPLE_COVER_PHOTO]: ['repo_id', 'people_id', 'selected_photo'],

[OPERATION_TYPE.MODIFY_SETTINGS]: ['repo_id', 'view_id', 'settings'],

Expand Down
9 changes: 9 additions & 0 deletions frontend/src/metadata/store/server-operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ class ServerOperator {
});
break;
}
case OPERATION_TYPE.SET_PEOPLE_COVER_PHOTO: {
const { people_id, selected_photo } = operation;
window.sfMetadataContext.setPeoplePhoto(people_id, selected_photo).then(res => {
callback({ operation });
}).catch(error => {
callback({ error: gettext('Failed to set people cover photo') });
});
break;
}

// tags
case OPERATION_TYPE.UPDATE_FILE_TAGS: {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/metadata/views/face-recognition/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const FaceRecognition = () => {
store.removePeoplePhotos(peopleId, peoplePhotos, { success_callback });
}, [store]);

const onSetPeoplePhoto = useCallback((peopleId, peoplePhoto) => {
store.setPeoplePhoto(peopleId, peoplePhoto);
}, [store]);

const openPeople = useCallback((people) => {
peopleRef.current = people;
const name = people._is_someone ? (people._name || gettext('Person image')) : gettext('Unknown people');
Expand Down Expand Up @@ -64,6 +68,7 @@ const FaceRecognition = () => {
onAddPeoplePhotos={onAddPeoplePhotos}
onRemovePeoplePhotos={onRemovePeoplePhotos}
onDeletePeoplePhotos={onDeletePeoplePhotos}
onSetPeoplePhoto={onSetPeoplePhoto}
/>
) : (
<Peoples peoples={peoples} onRename={onRename} onOpenPeople={openPeople} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import '../../gallery/index.css';

dayjs.extend(utc);

const PeoplePhotos = ({ view, people, onClose, onDeletePeoplePhotos, onAddPeoplePhotos, onRemovePeoplePhotos }) => {
const PeoplePhotos = ({ view, people, onClose, onDeletePeoplePhotos, onAddPeoplePhotos, onSetPeoplePhoto, onRemovePeoplePhotos }) => {
const [isLoading, setLoading] = useState(true);
const [isLoadingMore, setLoadingMore] = useState(false);
const [metadata, setMetadata] = useState({ rows: [] });
Expand Down Expand Up @@ -148,6 +148,11 @@ const PeoplePhotos = ({ view, people, onClose, onDeletePeoplePhotos, onAddPeople
});
}, [people, onAddPeoplePhotos, deletedByIds]);

const handleSetPeoplePhoto = useCallback((selectedImage) => {
const { id } = selectedImage;
onSetPeoplePhoto(people._id, id);
}, [people, onSetPeoplePhoto]);

const loadData = useCallback((view) => {
setLoading(true);
metadataAPI.getPeoplePhotos(repoID, people._id, 0, PER_LOAD_NUMBER).then(res => {
Expand Down Expand Up @@ -245,6 +250,7 @@ const PeoplePhotos = ({ view, people, onClose, onDeletePeoplePhotos, onAddPeople
onDelete={handelDelete}
onRemoveImage={people._is_someone ? handelRemove : null}
onAddImage={!people._is_someone ? handelAdd : null}
onSetPeoplePhoto={handleSetPeoplePhoto}
/>
</div>
);
Expand Down
Loading

0 comments on commit 2116209

Please sign in to comment.