Skip to content

Commit

Permalink
system-core: add new templates to display attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
SoulRiaper committed Dec 11, 2024
1 parent 79832a7 commit 51854fd
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 0 deletions.
95 changes: 95 additions & 0 deletions ontology/system-core/templates/v-ui_AttachmentTableRowTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import $ from 'jquery';
import Crypto from '/js/browser/crypto.js';
import IndividualModel from '/js/common/individual_model.js';

export const pre = async function (individual, template, container, mode, extra) {
const crypto = Crypto.getInstance();
try {
await crypto.init();
$('button#sign-attachments', template).removeClass('hidden');
} catch (error) {
console.log(error);
$('button#sign-attachments', template).remove();
return;
}

$('#sign-attachments', template).click(async () => {
try {
const filesToCryptoProcess = [individual];
await filesToCryptoProcess.reduce(async (acc, cur) => {
await acc;
if (!cur.hasValue('v-s:uid')) {
cur['v-s:uid'] = [crypto.genUUID()];
console.log(cur['v-s:uid']);
await cur.save();
}
}, Promise.resolve());
await crypto.addBatchSignature(filesToCryptoProcess);
} catch (err) {
console.log(err);
}
await checkSignatures();
});

let isAllSignedByUser = true;
async function checkSignatures() {
try {
isAllSignedByUser = true;
const signCreators = await individual.getChainValue('v-s:digitalSignature', 'v-s:creator');
const userCreated = signCreators.filter(creator => {
return creator.id == veda.appointment;
});
if (userCreated.length == 0) {
isAllSignedByUser = false;
}
} catch (err) {
console.log(err);
isAllSignedByUser = false;
}
if (isAllSignedByUser == false) {
$('#sign-attachments', template).removeAttr('disabled');
} else {
$('#sign-attachments', template).attr('disabled', 'disabled');
}
}
await checkSignatures();
};

export const html = `
<div class="row-container">
<div class="sign-action">
<button class="btn btn-primary btn-sm hidden" id="sign-attachments">
<i class="bi bi-pen-fill"></i>
</button>
</div>
<div class="file">
<div>
<a about="@" class="download-link" href="/files/@">
<span property="v-s:fileName"></span>
</a>
<small about="@" property="v-s:created"></small>
</div>
<small about="@" rel="v-s:creator" data-template="v-ui:LabelTemplate"></small>
</div>
<div class="signatures" about="@" class="digital-signature" rel="v-s:digitalSignature">
<div class="signature-row">
<div class="signature">
<div>
<a class="download-link" href="/files/@">
<span property="v-s:fileName"></span>
</a>
<small property="v-s:created"></small>
</div>
<small rel="v-s:creator" data-template="v-ui:LabelTemplate"></small>
</div>
<div class="sign-description">
<div rel="v-s:hasMchdInfo" data-template="v-ui:MchdLinkTemplate"></div>
</div>
</div>
</div>
<div class="comment">
<span class="view -edit search" property="rdfs:comment"></span>
<veda-control data-type="string" property="rdfs:comment" class="-view edit search" style="width: 100%;"></veda-control>
</div>
</div>
`;
145 changes: 145 additions & 0 deletions ontology/system-core/templates/v-ui_AttachmentTableTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import $ from 'jquery';

export const pre = async function (individual, template, container, mode, extra) {
template = $(template);
container = $(container);

const targetProperty = container.attr('target-property');
const disableHeader = container.attr('disable-header');
if (!targetProperty) {
throw new Error('Target property is not set');
}
if (!individual.hasValue(targetProperty)) {
template.hide();
return;
} else {
$('#table-body', template).attr('rel', targetProperty);
}
if (disableHeader) {
$('#table-header', template).hide();
}

individual.on(targetProperty, () => {
if (individual.hasValue(targetProperty)) {
template.show();
} else {
template.hide();
}
});
};

export const post = async function (individual, template, container, mode, extra) {
template = $(template);
container = $(container);

const withComment = container.attr('with-comment');
const signable = container.attr('with-btn');
const targetProperty = container.attr('target-property');

async function checkVisibility () {
if (!await isSignedFiles(individual[targetProperty])) {
$('.signatures', template).remove();
}
if (!withComment) {
$('.comment', template).remove();
}
if (!signable) {
$('.sign-action', template).remove();
}
}

async function isSignedFiles (files) {
for (const file of files) {
await file.load();
if (file.hasValue('v-s:digitalSignature')) {
return true;
}
}
return false;
}

checkVisibility();
individual.on(targetProperty, checkVisibility);
};


export const html = `
<div>
<style scoped>
.row-container {
display: flex;
border: 1px solid #ddd;
border-bottom: none;
}
.file {
flex: 1;
border-right: 1px solid #ddd;
padding: 8px;
}
.signatures {
flex: 2;
display: flex;
flex-direction: column;
min-height: 100%;
}
.signature-row {
display: flex;
border-bottom: 1px solid #ddd;
flex: 1;
}
.signature {
flex: 2;
padding: 8px;
border-right: 1px solid #ddd;
}
.sign-description {
max-width: 60px;
flex: 1;
padding: 8px;
text-align: center;
}
.signature:last-child, .description:last-child {
border-right: none;
}
.signature-row:last-child {
border-bottom: none;
}
.row-container:last-child {
border-bottom: 1px solid #ddd;
}
.comment {
flex: 1;
padding: 8px;
display: flex;
border-left: 1px solid #ddd;
align-items: center;
}
.sign-action {
flex: 1;
display: flex;
padding: 8px;
align-items: center;
border-right: 1px solid #ddd;
max-width: 100px;
}
</style>
<div class="row-container" id="table-header">
<div class="sign-action">
</div>
<div class="file">
<strong about="v-s:File" property="rdfs:label"></strong>
</div>
<div class="signatures">
<div class="signature-row">
<div class="signature">
<strong about="v-ui:DigitalSignatureBundle" property="rdfs:label"></strong>
</div>
</div>
</div>
<div class="comment">
<strong about="rdfs:comment" property="rdfs:label"></strong>
</div>
</div>
<div id="table-body" rel="v-s:attachment" data-template="v-ui:AttachmentTableRowTemplate" data-embedded="true"></div>
</div>
`;
17 changes: 17 additions & 0 deletions ontology/system-core/templates/v-ui_MchdLinkTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import $ from 'jquery';
import veda from '/js/common/veda.js';
import Backend from '/js/common/backend.js';

export const pre = function (individual, template, container, mode, extra) {
template = $(template);
container = $(container);

const placeDescription = individual['v-s:placeDescription'];
template.attr('href', placeDescription);
};

export const html = `
<a href="#" target="_blank">
<span>МЧД</span>
</a>
`;
18 changes: 18 additions & 0 deletions ontology/system-core/veda-ui.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -1028,4 +1028,22 @@ v-ui:AppointmentSwitchMenuTemplate
rdfs:label "Template for Main page class"@en ;
v-ui:template "v-ui_AppointmentSwitchMenuTemplate.js" ;
.
v-ui:AttachmentTableTemplate
rdf:type v-ui:ClassTemplate ;
rdfs:label "Табличный шаблон для вложений"@ru ;
rdfs:label "Attachment table template"@en ;
v-ui:template "v-ui_AttachmentTableTemplate.js" ;
.
v-ui:MchdLinkTemplate
rdf:type v-ui:ClassTemplate ;
rdfs:label "Шаблон для ссылки на МЧД"@ru ;
rdfs:label "Template for MCHD link"@en ;
v-ui:template "v-ui_MchdLinkTemplate.js" ;
.
v-ui:AttachmentTableRowTemplate
rdf:type v-ui:ClassTemplate ;
rdfs:label "Шаблон для строки таблицы вложений"@ru ;
rdfs:label "Template for attachment table row"@en ;
v-ui:template "v-ui_AttachmentTableRowTemplate.js" ;
.

0 comments on commit 51854fd

Please sign in to comment.