Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,23 @@ <h3 class="text-lg text-red-500">{{ 'project.metadata.addMetadata.notPublishedTe
</div>
}
<div class="cedar-editor-container">
@if (!cedarLoaded()) {
<osf-loading-spinner />
@if (readonly()) {
<cedar-artifact-viewer
#cedarViewer
[config]="cedarViewerConfig"
[templateObject]="template().attributes.template"
[instanceObject]="formData()"
></cedar-artifact-viewer>
} @else {
@if (readonly()) {
<cedar-artifact-viewer
#cedarViewer
[config]="cedarViewerConfig"
[templateObject]="template().attributes.template"
[instanceObject]="formData()"
></cedar-artifact-viewer>
} @else {
<cedar-embeddable-editor
#cedarEditor
[config]="cedarConfig"
[templateObject]="template().attributes.template"
[metadata]="formData()"
(change)="onCedarChange($event)"
(pointerover)="validateCedarMetadata()"
(keyup)="onCedarChange($event)"
></cedar-embeddable-editor>
}
<cedar-embeddable-editor
#cedarEditor
[config]="cedarConfig"
[templateObject]="template().attributes.template"
[metadata]="formData()"
(change)="onCedarChange($event)"
(pointerover)="validateCedarMetadata()"
(keyup)="onCedarChange($event)"
></cedar-embeddable-editor>
}
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Tooltip } from 'primeng/tooltip';

import { map, of } from 'rxjs';

import { CommonModule, isPlatformBrowser } from '@angular/common';
import { CommonModule } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
Expand All @@ -16,7 +16,6 @@ import {
inject,
input,
output,
PLATFORM_ID,
signal,
viewChild,
ViewEncapsulation,
Expand All @@ -25,7 +24,8 @@ import { toSignal } from '@angular/core/rxjs-interop';
import { ActivatedRoute } from '@angular/router';

import { ENVIRONMENT } from '@core/provider/environment.provider';
import { LoadingSpinnerComponent } from '@osf/shared/components/loading-spinner/loading-spinner.component';

import 'cedar-artifact-viewer';

import { CEDAR_CONFIG, CEDAR_VIEWER_CONFIG } from '../../constants';
import { CedarMetadataHelper } from '../../helpers';
Expand All @@ -38,7 +38,7 @@ import {

@Component({
selector: 'osf-cedar-template-form',
imports: [CommonModule, Button, TranslatePipe, Tooltip, Menu, LoadingSpinnerComponent],
imports: [CommonModule, Button, TranslatePipe, Tooltip, Menu],
templateUrl: './cedar-template-form.component.html',
styleUrl: './cedar-template-form.component.scss',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
Expand All @@ -65,8 +65,6 @@ export class CedarTemplateFormComponent {

private route = inject(ActivatedRoute);
readonly environment = inject(ENVIRONMENT);
private platformId = inject(PLATFORM_ID);
readonly cedarLoaded = signal<boolean>(false);

readonly recordId = signal<string>('');
readonly downloadUrl = signal<string>('');
Expand All @@ -93,15 +91,15 @@ export class CedarTemplateFormComponent {
effect(() => {
const tpl = this.template();
if (tpl?.attributes?.template) {
this.loadCedarLibraries().then(() => this.initializeCedar());
this.initializeCedar();
}
});

effect(() => {
const record = this.existingRecord();
this.schemaName.set(record?.embeds?.template.data.attributes.schema_name || '');
if (record) {
this.loadCedarLibraries().then(() => this.initializeCedar());
this.initializeCedar();
}
});
}
Expand Down Expand Up @@ -138,19 +136,6 @@ export class CedarTemplateFormComponent {
}
}

private async loadCedarLibraries(): Promise<void> {
if (!isPlatformBrowser(this.platformId) || this.cedarLoaded()) {
return;
}

try {
await Promise.all([import('cedar-artifact-viewer'), import('cedar-embeddable-editor')]);
this.cedarLoaded.set(true);
} catch {
this.cedarLoaded.set(false);
}
}

downloadMetadadaRecord() {
if (this.fileGuid()) {
window.open(`${this.environment.webUrl}/metadata/${this.fileGuid()}`)?.focus();
Expand Down Expand Up @@ -199,6 +184,7 @@ export class CedarTemplateFormComponent {
this.emitData.emit(finalData as CedarRecordDataBinding);
}
}

handleEmailShare(): void {
const url = window.location.href;
window.location.href = `mailto:?subject=${this.schemaName()}&body=${url}`;
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from '@osf/app.component';
import { appConfig } from '@osf/app.config';

import 'cedar-embeddable-editor';

bootstrapApplication(AppComponent, {
providers: [...appConfig.providers],
}).catch((err) =>
Expand Down