Skip to content

Commit

Permalink
fix import component
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmostafa committed Feb 26, 2025
1 parent 6603c04 commit b4997e9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
11 changes: 9 additions & 2 deletions CSETWebNg/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,8 @@ import { RolesChangedComponent } from './dialogs/roles-changed/roles-changed.com
import { AnalyticsResultsComponent } from './assessment/results/analytics-results/analytics-results.component';
import { firstValueFrom } from 'rxjs';
import { UpgradeComponent } from './assessment/upgrade/upgrade.component';
import { CodeEditorModule } from '@ngstack/code-editor';
import { ImportComponent } from './import/import.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -1228,7 +1230,8 @@ import { UpgradeComponent } from './assessment/upgrade/upgrade.component';
QuestionsReviewedComponent,
RolesChangedComponent,
AnalyticsResultsComponent,
UpgradeComponent
UpgradeComponent,
ImportComponent
],
bootstrap: [AppComponent], imports: [BrowserModule,
BrowserAnimationsModule,
Expand Down Expand Up @@ -1292,7 +1295,11 @@ import { UpgradeComponent } from './assessment/upgrade/upgrade.component';
TooltipModule,
SwiperModule,
EllipsisModule,
HotkeyModule.forRoot(),],
HotkeyModule.forRoot(),
CodeEditorModule.forRoot({
typingsWorkerUrl: 'assets/workers/typings-worker.js',
baseUrl: 'assets/monaco'
})],
providers: [
TranslocoService,
provideTranslocoScope('tutorial', 'reports'),
Expand Down
2 changes: 1 addition & 1 deletion CSETWebNg/src/app/import/import.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ <h4 class="panel-title px-2 py-1" style="color:white">
Warning: This will clear the code editor
</div>
</div>
</div> -->
</div>
</form>
</div>
</div>
Expand Down
52 changes: 29 additions & 23 deletions CSETWebNg/src/app/import/import.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,19 @@
//
////////////////////////////////
import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { CodeEditorComponent, CodeEditorService, CodeModel, provideCodeEditor } from '@ngstack/code-editor';
import { CodeEditorComponent, CodeEditorService, CodeModel } from '@ngstack/code-editor';
import { saveAs } from 'file-saver';
import { editor } from 'monaco-editor/esm/vs/editor/editor.api';
import { Subject, Subscription } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import screenfull from 'screenfull';
import { Screenfull } from "screenfull";
import { FileItem, FileUploader, FileUploadModule } from 'ng2-file-upload';
import { FileItem, FileUploader } from 'ng2-file-upload';
import { XmlCompletionItemProvider } from '../models/xmlCompletionItemProvider.model';
import { ConfigService } from '../services/config.service';
import { FileUploadClientService, LinkedSet } from '../services/file-client.service';
import { XmlFormatterFactory } from './formatting/xml-formatter';
import { XmlFormattingEditProvider } from './formatting/xml-formatting-edit-provider';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';


export class ImportFormData {
Expand All @@ -49,12 +47,7 @@ export class ImportFormData {
templateUrl: './import.component.html',
// eslint-disable-next-line
host: { class: 'd-flex flex-11a w-100' },
standalone: true,
imports: [CommonModule, CodeEditorComponent, FormsModule, FileUploadModule],
providers: [provideCodeEditor({
typingsWorkerUrl: 'assets/workers/typings-worker.js',
baseUrl: 'assets/monaco'
})]
standalone: false,
})
export class ImportComponent implements OnInit, OnDestroy {
public uploader: FileUploader;
Expand Down Expand Up @@ -371,20 +364,12 @@ export class ImportComponent implements OnInit, OnDestroy {
uri: 'http://custom/schema.xsd',
schema: s
});
if (t?.monaco?.languages) {

if (t?.monaco) {
this.monaco = t.monaco;
t.monaco.languages.registerCompletionItemProvider(
'xml',
new XmlCompletionItemProvider(t, s)
);
t.monaco.languages.registerDocumentFormattingEditProvider(
'xml',
new XmlFormattingEditProvider(XmlFormatterFactory.getXmlFormatter())
);
t.monaco.languages.registerDocumentRangeFormattingEditProvider(
'xml',
new XmlFormattingEditProvider(XmlFormatterFactory.getXmlFormatter())
);
this.registerXmlProviders(s);
} else {
console.warn("Monaco not fully initialized");
}
});
});
Expand All @@ -398,6 +383,27 @@ export class ImportComponent implements OnInit, OnDestroy {
});
}

private registerXmlProviders(schemaContent: string) {
try {
if (this.monaco?.languages) {
this.monaco.languages.registerCompletionItemProvider(
'xml',
new XmlCompletionItemProvider(this.monaco, schemaContent)
);
this.monaco.languages.registerDocumentFormattingEditProvider(
'xml',
new XmlFormattingEditProvider(XmlFormatterFactory.getXmlFormatter())
);
this.monaco.languages.registerDocumentRangeFormattingEditProvider(
'xml',
new XmlFormattingEditProvider(XmlFormatterFactory.getXmlFormatter())
);
}
} catch (err) {
console.error('Failed to register XML providers:', err);
}
}

public showError(): boolean {
if (this.state === 'Processing') {
return false;
Expand Down

0 comments on commit b4997e9

Please sign in to comment.