Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/registration-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Page {
questions: Question[];
type?: 'object';
description?: string;
clipboardCopyPaste: boolean;
}

export interface Schema {
Expand Down
12 changes: 9 additions & 3 deletions app/models/schema-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ export default class SchemaBlockModel extends OsfModel implements SchemaBlock {
@attr('number') index?: number;
@attr('string') pattern?: string;
@attr('boolean') spaceNormalization?: boolean;
@attr('boolean') autoDate?: boolean;
@attr('boolean') autoTitle?: boolean;
@attr('boolean') hideProjectmetadata?: boolean;
@attr('string') getRetrievalTitle?: string;
@attr('string') getRetrievalDate?: string;
@attr('boolean') concealmentPageNavigator?: boolean;
@attr('string') requiredAllCheck?: string;
@attr('boolean') multiLanguage?: boolean;
@attr('string') getRetrievalVersion?: string;
@attr('boolean') getEdit?: boolean;
@attr('boolean') sentence?: boolean;
@attr('string') rowAdditionCaption?: string;

@belongsTo('registration-schema', { inverse: 'schemaBlocks', async: false })
schema?: RegistrationSchemaModel;
Expand Down
7 changes: 4 additions & 3 deletions app/packages/registration-schema/get-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { SchemaBlock } from 'ember-osf-web/packages/registration-schema';
export function getPages(blocks: SchemaBlock[]) {
const pageArray = blocks.reduce(
(pages, block) => {
// instantiate first page if the schema doesn't start with a page-heading
if (pages.length === 0 && block.blockType !== 'page-heading'
&& (block.hideProjectmetadata === true || block.hideProjectmetadata === undefined)) {
&& (block.concealmentPageNavigator === true || block.concealmentPageNavigator === undefined)) {
const blankPage: SchemaBlock[] = [];
pages.push(blankPage);
}

const lastPage: SchemaBlock[] = pages.slice(-1)[0] || [];
const lastPage: SchemaBlock[] = pages.slice(-1)[0];
if (block.blockType === 'page-heading'
&& (block.hideProjectmetadata === false || block.hideProjectmetadata === undefined)) {
&& (block.concealmentPageNavigator === false || block.concealmentPageNavigator === undefined)) {
pages.push([block]);
} else {
lastPage.push(block);
Expand Down
2 changes: 2 additions & 0 deletions app/packages/registration-schema/get-schema-block-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function getSchemaBlockGroups(blocks: SchemaBlock[] | undefined) {
case 'jgn-program-name-ja-input':
case 'jgn-program-name-en-input':
case 'e-rad-award-funder-input':
case 'single-select-pulldown-input':
case 'pulldown-input':
case 'e-rad-award-number-input':
case 'e-rad-award-title-ja-input':
Expand All @@ -53,6 +54,7 @@ export function getSchemaBlockGroups(blocks: SchemaBlock[] | undefined) {
case 'e-rad-researcher-name-en-input':
case 'e-rad-bunnya-input':
case 'file-metadata-input':
case 'ad-metadata-input':
case 'date-input':
case 'section-heading':
case 'subsection-heading':
Expand Down
7 changes: 6 additions & 1 deletion app/packages/registration-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ export { getPages } from './get-pages';
export { getSchemaBlockGroups } from './get-schema-block-group';
export { SchemaBlock, SchemaBlockType } from './schema-block';
export { SchemaBlockGroup } from './schema-block-group';
export { buildValidation, buildMetadataValidations, setupEventForSyncValidation } from './validations';
export {
buildValidation,
buildMetadataValidations,
setupEventForSyncValidation,
setupEventForSyncValidation2,
} from './validations';
export {
FileReference,
RegistrationResponse,
Expand Down
8 changes: 6 additions & 2 deletions app/packages/registration-schema/page-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ import {
SchemaBlock,
SchemaBlockGroup,
setupEventForSyncValidation,
setupEventForSyncValidation2,
} from 'ember-osf-web/packages/registration-schema';
import { RegistrationResponse } from 'ember-osf-web/packages/registration-schema/registration-response';

export class PageManager {
changeset?: ChangesetDef;
schemaBlockGroups?: SchemaBlockGroup[];
pageHeadingText?: string;
hideProjectmetadata?: boolean;
concealmentPageNavigator?: boolean;
isVisited?: boolean;

constructor(pageSchemaBlocks: SchemaBlock[], registrationResponses: RegistrationResponse, node?: NodeModel) {
this.schemaBlockGroups = getSchemaBlockGroups(pageSchemaBlocks);
if (this.schemaBlockGroups) {
this.pageHeadingText = this.schemaBlockGroups[0].labelBlock!.displayText!;
this.hideProjectmetadata = this.schemaBlockGroups[0].labelBlock!.hideProjectmetadata!;
this.concealmentPageNavigator = this.schemaBlockGroups[0].labelBlock!.concealmentPageNavigator!;

this.isVisited = this.schemaBlockGroups.some(
({ registrationResponseKey: key }) => Boolean(key && (key in registrationResponses)),
Expand All @@ -36,8 +37,11 @@ export class PageManager {
lookupValidator(validations),
validations,
) as ChangesetDef;

setupEventForSyncValidation(this.changeset, this.schemaBlockGroups);

setupEventForSyncValidation2(this.changeset, this.schemaBlockGroups);

if (this.isVisited) {
this.changeset.validate();
}
Expand Down
11 changes: 9 additions & 2 deletions app/packages/registration-schema/schema-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type SchemaBlockType =
'jgn-program-name-ja-input' |
'jgn-program-name-en-input' |
'e-rad-award-funder-input' |
'single-select-pulldown-input' |
'pulldown-input' |
'e-rad-award-number-input' |
'e-rad-award-title-ja-input' |
Expand All @@ -27,6 +28,7 @@ export type SchemaBlockType =
'e-rad-researcher-name-en-input' |
'e-rad-bunnya-input' |
'file-metadata-input' |
'ad-metadata-input' |
'date-input' |
'array-input';

Expand All @@ -44,7 +46,12 @@ export interface SchemaBlock {
index?: number;
pattern?: string;
spaceNormalization?: boolean;
autoDate?: boolean;
autoTitle?: boolean;
hideProjectmetadata?: boolean;
getRetrievalTitle?: string;
getRetrievalDate?: string;
concealmentPageNavigator?: boolean;
requiredAllCheck?: string;
multiLanguage?: boolean;
getRetrievalVersion?: string;
rowAdditionCaption?: string;
}
41 changes: 41 additions & 0 deletions app/packages/registration-schema/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,47 @@ export function setupEventForSyncValidation(changeset: ChangesetDef, groups: Sch
});
}

export function setupEventForSyncValidation2(changeset: ChangesetDef, groups: SchemaBlockGroup[]) {
const requiredAllCheckGroups = groups
// ignore GRDM file specific fields
.filter((group: SchemaBlockGroup) => !group.registrationResponseKey
|| !group.registrationResponseKey.match(/^__responseKey_grdm-file:.+$/))
.filter((group: SchemaBlockGroup) => group.inputBlock && group.inputBlock.requiredAllCheck);

let isProcesing = false;

changeset.on('afterValidation', () => {
if (isProcesing) {
return;
}
isProcesing = true;

try {
const checkboxList = requiredAllCheckGroups.map(group => {
const registrationResponseKey: string = group.registrationResponseKey || '';
const value = changeset.get(registrationResponseKey);
return Array.isArray(value) && value.length === 1;
});

requiredAllCheckGroups
.forEach(group => {
if (!checkboxList.includes(false)) {
const todayDate = `${new Date().getFullYear()}/${
String(new Date().getMonth() + 1).padStart(2, '0')
}/${
String(new Date().getDate()).padStart(2, '0')
}`;
changeset.set(`__responseKey_${group.inputBlock!.requiredAllCheck}`, todayDate);
} else {
changeset.set(`__responseKey_${group.inputBlock!.requiredAllCheck}`, '');
}
});
} finally {
isProcesing = false;
}
});
}

export function validateNodeLicense() {
return async (_: unknown, __: unknown, ___: unknown, changes: DraftRegistration, content: DraftRegistration) => {
let validateLicenseTarget = await content.license;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ export default class ContributorList extends Component {
this.set('totalContributors', nextPage.meta.total);
} else {
this.set('page', 1);
const firstPage = yield this.node.bibliographicContributors;
const firstPage = yield this.node.queryHasMany(
'bibliographicContributors',
{
fields: {
users: 'full_name,given_name,family_name,id,links',
},
page: { size: 10 },
},
);
this.setProperties({
displayedContributors: firstPage.toArray(),
totalContributors: firstPage.meta.total,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
shouldShowMessages=this.shouldShowMessages
disabled=this.disabled
)
autodate=(
component
'validated-input/autodate'
changeset=@changeset
shouldShowMessages=this.shouldShowMessages
disabled=this.disabled
)
recaptcha=(
component
'validated-input/recaptcha'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,29 @@ import { and, or } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import Media from 'ember-responsive';

import DS from 'ember-data';
import Intl from 'ember-intl/services/intl';
import { layout } from 'ember-osf-web/decorators/component';
import DraftRegistration from 'ember-osf-web/models/draft-registration';
import CurrentUser from 'ember-osf-web/services/current-user';
import Toast from 'ember-toastr/services/toast';

import styles from './styles';
import template from './template';

@tagName('')
@layout(template, styles)
export default class RegistriesSideNav extends Component {
@service store!: DS.Store;
draftRegistrations: DraftRegistration[] = [];
// registrationSchema: RegistrationSchema[] = [];
@service toast!: Toast;
format?: string = '';

@service media!: Media;
@service intl!: Intl;
@service currentUser!: CurrentUser;
// changeset!: ChangesetDef;

// Optional params
onLinkClicked?: () => void;
Expand All @@ -27,8 +41,84 @@ export default class RegistriesSideNav extends Component {
@and('isCollapseAllowed', 'shouldCollapse')
isCollapsed!: boolean;

@service router!: any;
disableButtons = false;
pageTitle = '';
jsonData = '';

constructor(...args: any[]) {
super(...args);
this.handleRouteChange();
if (this.router && typeof this.router.on === 'function') {
this.router.on('routeDidChange', this.handleRouteChange.bind(this));
}
}

@action
toggle() {
this.toggleProperty('shouldCollapse');
}

@action
async handleRouteChange() {
const currentUrl = window.location.href;
const urlParts = currentUrl.split('/');
const lastPartWithQuery = urlParts[urlParts.length - 1];
const metadataTitle = lastPartWithQuery.split('?')[0];
const cleanedTitle = metadataTitle.replace(/^\d+-/, '');
const title = decodeURIComponent(cleanedTitle.replace(/-/g, ' '));
this.set('pageTitle', title.trim().toLowerCase());
const allSchemas = await this.store.findAll('registration-schema');
const matchedSchema = allSchemas.find((schema: any) => schema.schema.pages.some((page: any) => (
page.title.trim().toLowerCase() === title.trim().toLowerCase()
&& page.clipboardCopyPaste === false)));

if (matchedSchema) {
this.set('disableButtons', true);
} else {
this.set('disableButtons', false);
}
}

@action
async copyToClipboard() {
const currentUrl = window.location.href;
const idRegex = /\/drafts\/([a-f0-9]{24})/;
const match = currentUrl.match(idRegex);
if (match && match[1]) {
const draftId = match[1];

const draftRegistration = await this.store.findRecord('draft-registration', draftId);

if (draftRegistration) {
const registrationMetadata = await draftRegistration.registrationMetadata;
const metadata: { [key: string]: any } = {};
const registrationSchema = await draftRegistration.registrationSchema;
for (const page of registrationSchema.schema.pages) {
if (page.title.trim().toLowerCase() !== this.pageTitle && !page.clipboardCopyPaste) {
continue;
}

for (const question of page.questions) {
Object.keys(registrationMetadata).forEach(key => {
if (key === question.qid && !key.startsWith('grdm-')) {
if (question.format === 'multiselect' && registrationMetadata[key].value === '') {
metadata[key] = [];
} else {
metadata[key] = registrationMetadata[key].value;
}
}
});
}
}
this.jsonData = JSON.stringify(metadata);
if (this.jsonData === '{}' || Object.keys(JSON.parse(this.jsonData)).length === 0) {
this.toast.warning(this.intl.t('registries.drafts.draft.form.warning_noautosave'));
} else {
await navigator.clipboard.writeText(this.jsonData);
this.toast.success(this.intl.t('registries.drafts.draft.form.clipboard_copied'));
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
.LabelWrapper {
justify-content: space-between;
display: inline-flex;
display: flex;
width: 100%;
padding-left: 10px;
font-weight: 700;
white-space: inherit;
white-space: normal;
word-wrap: break-word;
overflow: hidden;

&:hover {
Expand All @@ -16,6 +17,8 @@
float: left;
overflow: hidden;
text-overflow: ellipsis;
white-space: normal;
word-wrap: break-word;

&:hover {
overflow: visible;
Expand All @@ -24,4 +27,7 @@

.Count {
float: right;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,23 @@
</ExpandButton>
{{/let}}
{{/if}}

{{!-- model1 :{{@model}}
model2 : {{model}}
{{#each @model as |item index|}}
{{#if (eq index 1)}}
<p>test >>{{item}}</p>
{{/if}}
{{/each}}
test --}}
<OsfButton
data-test-copy-to-clipboard
data-analytics-name='Copy to clipboard'
@onClick={{action this.copyToClipboard}}
@disabled={{this.disableButtons}}
@type='info'
>
{{t 'registries.drafts.draft.form.copy_to_clipboard'}}
</OsfButton>

</nav>
Loading