File

src/app/modules/dashboard/components/add-summary-modal/add-summary-modal.component.ts

Implements

OnInit OnDestroy AfterViewInit

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(fb: UntypedFormBuilder)
Parameters :
Name Type Optional
fb UntypedFormBuilder No

Inputs

input
Type : ISummaryObject

Outputs

closeModalEvent
Type : EventEmitter
submitButtonEvent
Type : EventEmitter

Methods

Public closeModal
closeModal()
Returns : void
Public handleSubmitButton
handleSubmitButton()
Returns : void
Private initForm
initForm()
Returns : void
ngAfterViewInit
ngAfterViewInit()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Public resetForm
resetForm()
Returns : void

Properties

Public editorInstance
Type : any
Public editorRef
Type : ElementRef
Decorators :
@ViewChild('editor')
Public summaryFormGroup
Type : UntypedFormGroup
Private toolbarItems
Type : []
Default value : ['undo', 'redo', 'bold', 'italic', 'blockQuote', 'heading', 'link', 'numberedList', 'bulletedList', 'fontFamily', 'fontSize', 'fontColor', 'fontBackgroundColor', 'underline', 'subscript', 'superscript', 'insertTable', 'tableColumn', 'tableRow', 'mergeTableCells']
import { UntypedFormGroup, UntypedFormBuilder, Validators } from '@angular/forms';
import { Component, OnInit, EventEmitter, Output, Input, OnDestroy, ViewChild, AfterViewInit, ElementRef } from '@angular/core';
import * as ClassicEditor from '@project-sunbird/ckeditor-build-classic';
import { ISummaryObject } from '../../interfaces';

@Component({
  selector: 'app-add-summary-modal',
  templateUrl: './add-summary-modal.component.html',
  styleUrls: ['./add-summary-modal.component.scss']
})
export class AddSummaryModalComponent implements OnInit, OnDestroy, AfterViewInit {

  @Output() submitButtonEvent = new EventEmitter();
  @Input() input: ISummaryObject;
  @Output() closeModalEvent = new EventEmitter();
  @ViewChild('editor') public editorRef: ElementRef;
  public editorInstance: any;

  private toolbarItems = ['undo', 'redo', 'bold', 'italic', 'blockQuote', 'heading', 'link', 'numberedList', 'bulletedList', 'fontFamily',
    'fontSize', 'fontColor', 'fontBackgroundColor', 'underline', 'subscript', 'superscript', 'insertTable', 'tableColumn', 'tableRow', 'mergeTableCells'];

  public summaryFormGroup: UntypedFormGroup;

  constructor(private fb: UntypedFormBuilder) { }

  ngOnInit() {
    this.initForm();
  }

  ngAfterViewInit() {
    ClassicEditor.create(this.editorRef.nativeElement, {
      toolbar: this.toolbarItems
    })
      .then(editor => {
        this.editorInstance = editor;
        if (this.input.summary) {
          const editorDataInput = this.input.summary
            .replace(/(<img("[^"]*"|[^\/">])*)>/gi, '$1/>')
            .replace(/(<br("[^"]*"|[^\/">])*)>/gi, '$1/>');
          this.editorInstance.setData(editorDataInput);
        }
        editor.model.document.on('change', (eventInfo, batch) => {
          this.summaryFormGroup.controls.summary.setValue(editor.getData());
        });
      })
      .catch(err => { console.error(err); });
  }

  ngOnDestroy() {
    this.closeModal();
  }

  public handleSubmitButton(): void {
    if (this.summaryFormGroup.valid) {
      this.submitButtonEvent.emit({
        summary: this.summaryFormGroup.get('summary').value,
        type: this.input.type,
        ...(this.input.type === 'chart' && { index: this.input.index, chartId: this.input.chartId })
      });
    }
  }

  private initForm(): void {
    this.summaryFormGroup = this.fb.group({
      summary: ['', Validators.required]
    });
  }

  public resetForm(): void {
    this.summaryFormGroup.reset();
    this.editorInstance.setData('');
  }

  public closeModal(): void {
    this.closeModalEvent.emit(true);
  }
}
<div class="sb-mat__modal sb-modal-addsummary">
  <div mat-dialog-title class="mb-0">
    <div class="title" tabindex="0">{{input?.title}}</div>
    <button aria-label="close dialog" mat-dialog-close class="close-btn"></button>
  </div>

  <div class="sb-mat__modal__content o-x-hide">
    <div class="sb-field-group" [formGroup]="summaryFormGroup">
      <div class="sb-field relative" #editor>
        <textarea #editor required name="moretext" class="sb-form-control" [placeholder]="input?.title" rows="5"
          style="resize: none;"></textarea>
      </div>
    </div>
  </div>

  <mat-dialog-actions class="sb-mat__modal__actions">
    <button (click)="handleSubmitButton()" tabindex="0" [disabled]="!summaryFormGroup.valid"
      class="sb-btn sb-btn-normal sb-btn-primary" #submitButton>
      Submit
    </button>
    <button (click)="resetForm()" tabindex="0" class="sb-btn sb-btn-normal sb-btn-outline-primary">
      Reset
    </button>
  </mat-dialog-actions>
</div>

./add-summary-modal.component.scss

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""