Skip to content

Commit

Permalink
feat: implements #222, #223, #226.
Browse files Browse the repository at this point in the history
refactor: various element class and css tweaks to create a more tighter layout in
properties sidebar (right side)
  • Loading branch information
jorisvanzundert committed Aug 6, 2024
1 parent 00e001a commit 3fff40d
Show file tree
Hide file tree
Showing 13 changed files with 523 additions and 19 deletions.
17 changes: 15 additions & 2 deletions frontend/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@
<div class="container-fluid">
<div class="row">
<div id="sidebar-menu" class="col-2 sidebar-menu bg-light footer-branding collapse show">
<div class="position-sticky pt-3">
<div class="position-sticky pt-2">
<h6
class="sidebar-menu-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
class="sidebar-menu-heading d-flex justify-content-between align-items-center px-3 mt-2 mb-1 text-muted">
<span>Text directory</span>
<a
class="link-secondary"
Expand All @@ -140,6 +140,7 @@
</div>

<div id="sidebar-properties" class="col-3 sidebar-properties bg-light">
<relation-types></relation-types>
<property-table-view id="property-table-view"></property-table-view>
<section-properties-view></section-properties-view>
<stemweb-job-status></stemweb-job-status>
Expand Down Expand Up @@ -329,6 +330,18 @@
src="./src/js/modules/dashboard/relationmapper/sectionSelectors.js"
type="application/javascript"
></script>
<script
src="./src/js/modules/dashboard/relationmapper/relationTypes.js"
type="application/javascript"
></script>
<script
src="./src/js/modules/dashboard/relationmapper/deleteRelationType.js"
type="application/javascript"
></script>
<script
src="./src/js/modules/dashboard/relationmapper/editRelationType.js"
type="application/javascript"
></script>

</body>
</html>
67 changes: 66 additions & 1 deletion frontend/www/src/css/dashboard-stemmaweb.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,58 @@
--bs-btn-disabled-border-color: #adb5bf;
}

.relation-colors {
--color-sky: #a6cee3;
--color-blue: #1f78b4;
--color-mint: #b2df8a;
--color-green: #33a02c;
--color-pink: #fb9a99;
--color-red: #e31a1c;
--color-peach: #fdbf6f;
--color-orange: #ff7f00;
--color-plum: #cab2d6;
--color-purple: #6a3d9a;
--color-lemon: #ffff99;
--color-brown: #b15928;
}

span.relation-colors.color-sky svg.feather.feather-square {
fill: var(--color-sky);
}
span.relation-colors.color-blue svg.feather.feather-square {
fill: var(--color-blue);
}
span.relation-colors.color-mint svg.feather.feather-square {
fill: var(--color-mint);
}
span.relation-colors.color-green svg.feather.feather-square {
fill: var(--color-green);
}
span.relation-colors.color-pink svg.feather.feather-square {
fill: var(--color-pink);
}
span.relation-colors.color-red svg.feather.feather-square {
fill: var(--color-red);
}
span.relation-colors.color-peach svg.feather.feather-square {
fill: var(--color-peach);
}
span.relation-colors.color-orange svg.feather.feather-square {
fill: var(--color-orange);
}
span.relation-colors.color-plum svg.feather.feather-square {
fill: var(--color-plum);
}
span.relation-colors.color-purple svg.feather.feather-square {
fill: var(--color-purple);
}
span.relation-colors.color-lemon svg.feather.feather-square {
fill: var(--color-lemon);
}
span.relation-colors.color-brown svg.feather.feather-square {
fill: var(--color-brown);
}

.brand-dark {
color: rgba(255, 255, 255, 0.7);
}
Expand Down Expand Up @@ -405,7 +457,7 @@ social-login-options .btn {
font-size: calc( var(--bs-btn-font-size) * 4);
}

delete-section-button .btn-outline-danger {
delete-section-button .btn-outline-danger, delete-relation-type-button .btn-outline-danger {
color: var(--bs-btn-color);
padding-right: 0.5em;
}
Expand Down Expand Up @@ -433,6 +485,19 @@ relation-mapper {
width: 100%;
}

/* relation-types div {
display: none;
opacity: 0;
} */

.relation-type-name-cell {
width: 100%;
}

.relation-type-buttons-cell {
white-space: nowrap;
}

button.selected-view {
color: #fff;
background-color: #87aade;
Expand Down
2 changes: 1 addition & 1 deletion frontend/www/src/js/modules/common/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function fadeToDisplayNone( element, options={} ){
}
} );
} else {
d3.select( '#sidebar-menu' ).node().style.removeProperty( 'display' )
d3.select( element ).node().style.removeProperty( 'display' )
d3.select( element )
.transition()
.delay( usedOptions.delay )
Expand Down
36 changes: 36 additions & 0 deletions frontend/www/src/js/modules/common/service/stemmarestService.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,40 @@ class StemmarestService extends BaseService {
return this.fetch(`/api/tradition/${traditionId}/section/${sectionId}/dot`);
}

/**
* Fetches the relations for a section.
*
* @param {string} traditionId
* * @param {string} sectionId
* @returns {Promise<BaseResponse<T>>}
* @see {@link https://dhuniwien.github.io/tradition_repo/|Stemmarest Endpoint: /tradition/[tradId]/section/[sectionId]/relations/
*/
getSectionRelations( traditionId, sectionId ) {
return this.fetch(`/api/tradition/${traditionId}/section/${sectionId}/relations`);
}

/**
* Fetches the relation types for a tradition.
*
* @param {string} traditionId
* @returns {Promise<BaseResponse<T>>}
* @see {@link https://dhuniwien.github.io/tradition_repo/|Stemmarest Endpoint: /tradition/[tradId]/relationtypes/
*/
getRelationTypes( traditionId ) {
return this.fetch( `/api/tradition/${traditionId}/relationtypes` );
}

/**
* Deletes a particular relation type for a tradition.
*
* @param {string} traditionId
* @returns {Promise<BaseResponse<T>>}
* @see {@link https://dhuniwien.github.io/tradition_repo/|Stemmarest Endpoint: /tradition/[tradId]/relationtypes/
*/
deleteRelationType( traditionId, relationName ) {
return this.fetch( `/api/tradition/${traditionId}/relationtype/${relationName}`, {
method: 'DELETE'
} );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/** @typedef {import('@types/stemmaweb').BaseResponse} BaseResponse */

/**
* Object to interact with the Stemmarest Middleware's API through high-level
* functions.
*
* @type {StemmarestService}
*/
const deleteRelationTypeService = stemmarestService;

class DeleteRelationType extends HTMLElement {

#name = '';

constructor( relationTypeData ) {
super();
this.#name = relationTypeData.name;
this.addEventListener( 'click', this.handleDelete );
}

connectedCallback() {
this.render();
}

handleDelete() {
const { selectedTradition: tradition } = TRADITION_STORE.state;
StemmawebDialog.show(
'Delete Relation Type',
`<p>Are you sure you want to delete the relation type <span class="fst-italic">${this.#name}</span>?</p>`,
{
onOk: () => {
deleteRelationTypeService.deleteRelationType( tradition.id, this.#name ).then( (res) => {
if (res.success) {
document.querySelector( 'relation-types' ).renderRelationTypes( {'display': 'block', 'opacity': 1 } );
StemmawebAlert.show(
`<p class="d-inline">Deleted relation type <span class="fst-italic">${this.#name}</span></p>`,
'success'
);
// SECTION_STORE.sectionDeleted( section.id, tradition.id );
} else {
StemmawebAlert.show(
`Error during deletion: ${res.message}`,
'danger'
);
}
});
}
},
{
okLabel: 'Yes, delete it',
okType: 'danger',
closeLabel: 'Cancel',
closeType: 'secondary'
}
);
}

render() {
this.innerHTML = `
<a
class="link-secondary"
href="#"
aria-label="Delete relation type"
><span class="btn-outline-danger">${feather.icons['trash-2'].toSvg()}</span></a>
`;
}

}

customElements.define( 'delete-relation-type-button', DeleteRelationType );
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/** @typedef {import('@types/stemmaweb').BaseResponse} BaseResponse */

/**
* Object to interact with the Stemmarest Middleware's API through high-level
* functions.
*
* @type {StemmarestService}
*/
const editRelationTypeService = stemmarestService;

class EditRelationType extends HTMLElement {
constructor() {
super();
this.addEventListener( 'click', this.showDialog );
}

/**
* @param {Tradition} tradition Tradition to render the metadata for.
* @returns {MetaItem[]} Array of metadata items to display on a form.
*/
static metadataFromTradition(tradition) {
const metadata = PropertyTableView.metadataFromTradition(tradition);
metadata.push({
label: PropertyTableView.traditionMetadataLabels.name,
value: tradition.name,
inputOptions: { control: 'text', size: 40, required: true }
});
return metadata;
}

connectedCallback() {
this.render();
}

/**
* This helper ensures the modal is placed nicely fit with the properties
* sidebar.
*
* @returns {string} String representation of the needed properties of the
* style attribute.
* @todo: Add responsiveness on resize.
*/
#createDialogStyle() {
const width = $('sidebar-properties').getBoundingClientRect().width;
return (
`margin-right: 0px; width: ${width}px; margin-top: 50px;`
);
}

showDialog() {
const metaItems = PropertyTableView.sortedMetaItems(
EditProperties.metadataFromTradition( STEMMA_STORE.state.tradition )
);
const modal_body = `
<form
id="edit-tradition-properties-form"
class="needs-validation"
novalidate=""
>
${ metaItems.map( formControlFactory.renderFormControl ).join( '\n' ) }
</form>
`;
StemmawebDialog.show(
'Edit relation type',
modal_body,
{ onOk: this.processForm },
{
okLabel: 'Save',
elemStyle: this.#createDialogStyle()
}
);
}

/**
* @returns {{
* name: string;
* userId: string;
* language: string | null;
* direction: string;
* isPublic: boolean;
* }}
*/
static #extractFormValuesTradition() {
const name = $('name_input').value;
const language = $('language_input').value || null;
const direction = $('direction_input').value;
const isPublic = $('access_input').checked;
return { name, language, direction, isPublic };
}

/** @returns {Promise} */
processForm() {
const form = document.querySelector('#edit-tradition-properties-form');
if (form.checkValidity()) {
const values = Object.values(
EditRelationType.#extractFormValuesTradition()
);
const tradId = TRADITION_STORE.state.selectedTradition.id;
const userId = AUTH_STORE.state.user ? AUTH_STORE.state.user.id : null;
return editRelationTypeService
.updateTraditionMetadata( userId, tradId, ...values )
.then(EditRelationType.#handleUpdateTraditionMetadataResponse);
} else {
form.classList.add('was-validated');
return Promise.resolve({
success: false,
message: 'Form validation error.'
});
}
}

/** @param {BaseResponse<T>} resp */
static #handleUpdateTraditionMetadataResponse(resp) {
if (resp.success) {
StemmawebAlert.show('Metadata properties updated.', 'success');
TRADITION_STORE.updateTradition(resp.data);
return Promise.resolve({
success: true,
message: 'Metadata properties updated.'
});
} else {
StemmawebAlert.show(`Error: ${resp.message}`, 'danger');
return Promise.resolve({
success: false,
message: resp.message
});
}
}

render() {
this.innerHTML = `
<a
class="link-secondary"
href="#"
aria-label="Edit tradition properties"
>
<span>${feather.icons['edit'].toSvg()}</span>
</a>
`;
}
}

customElements.define('edit-relation-type-button', EditRelationType);
Loading

0 comments on commit 3fff40d

Please sign in to comment.