model

import { ChangeDetectorRef, Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
import {
    ClassicEditor,
    AccessibilityHelp,
    Alignment,
    AutoLink,
    Autosave,
    Bold,
    Essentials,
    GeneralHtmlSupport,
    Indent,
    IndentBlock,
    Italic,
    Link,
    List,
    Paragraph,
    SelectAll,
    Style,
    Undo,
    type EditorConfig
} from 'ckeditor5';
import { DTAnswerDetails, DtDetails } from '../model/dt-details.model';
import { CommonModule } from '@angular/common';
import { DtDetailsCopy, DtQuestionDetails } from '../model/dt-details-copy.model';



@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet,CKEditorModule,CommonModule],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent {
  title = 'ckeditor5';
  public Editor = ClassicEditor;
  // public editorConfig = {
  //   toolbar: ['bold', 'italic', 'underline', 'link']
  // };
  dtDetails1: DtDetails = new DtDetails(); // Correctly typed and initialized
  dtDetails2: DtDetailsCopy = new DtDetailsCopy(); // New model to copy data into
  constructor(private changeDetector: ChangeDetectorRef,) {}

    public isLayoutReady = false;
    public config: EditorConfig = {};
  public ngAfterViewInit(): void {
        this.config = {
            toolbar: {
                items: [
                    'undo',
                    'redo',
                    '|',
                    'selectAll',
                    '|',
                    'style',
                    '|',
                    'bold',
                    'italic',
                    '|',
                    'link',
                    '|',
                    'alignment',
                    '|',
                    'bulletedList',
                    'numberedList',
                    'outdent',
                    'indent',
                    '|',
                    'accessibilityHelp'
                ],
                shouldNotGroupWhenFull: false
            },
            plugins: [
                AccessibilityHelp,
                Alignment,
                AutoLink,
                Autosave,
                Bold,
                Essentials,
                GeneralHtmlSupport,
                Indent,
                IndentBlock,
                Italic,
                Link,
                List,
                Paragraph,
                SelectAll,
                Style,
                Undo
            ],
            htmlSupport: {
                allow: [
                    {
                        name: /^.*$/,
                        styles: true,
                        attributes: true,
                        classes: true
                    }
                ]
            },
            initialData:
                '<h2>Congratulations on setting up CKEditor 5! 🎉</h2>\n<p>\n    You\'ve successfully created a CKEditor 5 project. This powerful text editor will enhance your application, enabling rich text editing\n    capabilities that are customizable and easy to use.\n</p>\n<h3>What\'s next?</h3>\n<ol>\n    <li>\n        <strong>Integrate into your app</strong>: time to bring the editing into your application. Take the code you created and add to your\n        application.\n    </li>\n    <li>\n        <strong>Explore features:</strong> Experiment with different plugins and toolbar options to discover what works best for your needs.\n    </li>\n    <li>\n        <strong>Customize your editor:</strong> Tailor the editor\'s configuration to match your application\'s style and requirements. Or even\n        write your plugin!\n    </li>\n</ol>\n<p>\n    Keep experimenting, and don\'t hesitate to push the boundaries of what you can achieve with CKEditor 5. Your feedback is invaluable to us\n    as we strive to improve and evolve. Happy editing!\n</p>\n<h3>Helpful resources</h3>\n<ul>\n    <li>📝 <a href="https://orders.ckeditor.com/trial/premium-features">Trial sign up</a>,</li>\n    <li>📕 <a href="https://ckeditor.com/docs/ckeditor5/latest/installation/index.html">Documentation</a>,</li>\n    <li>⭐️ <a href="https://github.com/ckeditor/ckeditor5">GitHub</a> (star us if you can!),</li>\n    <li>🏠 <a href="https://ckeditor.com">CKEditor Homepage</a>,</li>\n    <li>🧑‍💻 <a href="https://ckeditor.com/ckeditor-5/demo/">CKEditor 5 Demos</a>,</li>\n</ul>\n<h3>Need help?</h3>\n<p>\n    See this text, but the editor is not starting up? Check the browser\'s console for clues and guidance. It may be related to an incorrect\n    license key if you use premium features or another feature-related requirement. If you cannot make it work, file a GitHub issue, and we\n    will help as soon as possible!\n</p>\n',
            link: {
                addTargetToExternalLinks: true,
                defaultProtocol: 'https://',
                decorators: {
                    toggleDownloadable: {
                        mode: 'manual',
                        label: 'Downloadable',
                        attributes: {
                            download: 'file'
                        }
                    }
                }
            },
            placeholder: 'Type or paste your content here!',
            style: {
                definitions: [
                    {
                        name: 'Article category',
                        element: 'h3',
                        classes: ['category']
                    },
                    {
                        name: 'Title',
                        element: 'h2',
                        classes: ['document-title']
                    },
                    {
                        name: 'Subtitle',
                        element: 'h3',
                        classes: ['document-subtitle']
                    },
                    {
                        name: 'Info box',
                        element: 'p',
                        classes: ['info-box']
                    },
                    {
                        name: 'Side quote',
                        element: 'blockquote',
                        classes: ['side-quote']
                    },
                    {
                        name: 'Marker',
                        element: 'span',
                        classes: ['marker']
                    },
                    {
                        name: 'Spoiler',
                        element: 'span',
                        classes: ['spoiler']
                    },
                    {
                        name: 'Code (dark)',
                        element: 'pre',
                        classes: ['fancy-code', 'fancy-code-dark']
                    },
                    {
                        name: 'Code (bright)',
                        element: 'pre',
                        classes: ['fancy-code', 'fancy-code-bright']
                    }
                ]
            }
        };

        this.isLayoutReady = true;
        this.changeDetector.detectChanges();
         // Example Data Binding - initialize DtDetails data
         this.initializeDtDetailsData();
         this.copyModelData(); // Copy data from dtDetails1 to dtDetails2
         this.getAllData();
    }
   
    private initializeDtDetailsData(): void {
        this.dtDetails1.Toolid = 1;
        this.dtDetails1.Groupid = 1001;
        this.dtDetails1.Toolname = "Tool Name Example";
        this.dtDetails1.Creadtedby = "User123";
   
        // Add two questions to the dtDetails model
        this.dtDetails1.quetionDeatils = [
          {
            queid: 1,
            QuestionText: "What is your favorite color?",
            QuestionDetailsId: "Q001",
            toolid: 1,
            CreatedBy: "User123",
            AnswerDetails: [
              { ansid: 1, ansDetailsId: "A001", AnswerText: "Red" },
              { ansid: 2, ansDetailsId: "A002", AnswerText: "Blue" },
              { ansid: 3, ansDetailsId: "A003", AnswerText: "Green" }
            ]
          },
          {
            queid: 2,
            QuestionText: "What is your favorite fruit?",
            QuestionDetailsId: "Q002",
            toolid: 1,
            CreatedBy: "User123",
            AnswerDetails: [
              { ansid: 1, ansDetailsId: "A004", AnswerText: "Apple" },
              { ansid: 2, ansDetailsId: "A005", AnswerText: "Banana" },
              { ansid: 3, ansDetailsId: "A006", AnswerText: "Orange" }
            ]
          }
        ];
      }
       // Function to deep copy data from dtDetails1 to dtDetails2
  copyModelData() {
   // this.dtDetails2 = JSON.parse(JSON.stringify(this.dtDetails1));
    //console.log(this.dtDetails2)
 // Copy simple properties
 this.dtDetails2.Toolid = this.dtDetails1.Toolid;
 this.dtDetails2.Groupid = this.dtDetails1.Groupid;
 this.dtDetails2.Toolname = this.dtDetails1.Toolname;
 this.dtDetails2.Creadtedby = this.dtDetails1.Creadtedby;

 // Copy quetionDeatils array
 this.dtDetails2.quetionDeatils = [];
 for (let question of this.dtDetails1.quetionDeatils) {
   // Create a new DtQuestionDeatils instance for each question
   let newQuestion = new DtQuestionDetails();
   newQuestion.queid = question.queid;
   newQuestion.QuestionText = question.QuestionText;
   newQuestion.QuestionDetailsId = question.QuestionDetailsId;
   newQuestion.toolid = question.toolid;
   newQuestion.CreatedBy = question.CreatedBy;

   // Copy AnswerDetails array for each question
   newQuestion.AnswerDetails = [];
   for (let answer of question.AnswerDetails) {
     // Create a new DTAnswerDetails instance for each answer
     let newAnswer = new DTAnswerDetails();
     newAnswer.ansid = answer.ansid;
     newAnswer.ansDetailsId = answer.ansDetailsId;
     newAnswer.AnswerText = answer.AnswerText;
     newQuestion.AnswerDetails.push(newAnswer);
   }

   // Push the copied question into dtDetails2's question details array
   this.dtDetails2.quetionDeatils.push(newQuestion);
   console.log(this.dtDetails2);
 }

  }
  getAllData(): DtDetails {
    let copiedData = new DtDetails();
 
    // Copy simple properties
    copiedData.Toolid = this.dtDetails1.Toolid;
    copiedData.Groupid = this.dtDetails1.Groupid;
    copiedData.Toolname = this.dtDetails1.Toolname;
    copiedData.Creadtedby = this.dtDetails1.Creadtedby;
 
    // Copy quetionDeatils array
    copiedData.quetionDeatils = [];
    for (let question of this.dtDetails1.quetionDeatils) {
      let newQuestion = new DtQuestionDetails();
      newQuestion.queid = question.queid;
      newQuestion.QuestionText = question.QuestionText;
      newQuestion.QuestionDetailsId = question.QuestionDetailsId;
      newQuestion.toolid = question.toolid;
      newQuestion.CreatedBy = question.CreatedBy;
 
      // Copy AnswerDetails array
      newQuestion.AnswerDetails = [];
      for (let answer of question.AnswerDetails) {
        let newAnswer = new DTAnswerDetails();
        newAnswer.ansid = answer.ansid;
        newAnswer.ansDetailsId = answer.ansDetailsId;
        newAnswer.AnswerText = answer.AnswerText;
        newQuestion.AnswerDetails.push(newAnswer);
      }
 
      copiedData.quetionDeatils.push(newQuestion);
    }
    console.log(copiedData);
    return copiedData;

  }
 
  // Usage
  //this.dtDetails2 = this.getAllData();
 
 
}

_____________model.ts--------
export class DtDetailsCopy {
        Toolid: any;
        Groupid: any;
        Toolname?: string;
        quetionDeatils: DtQuestionDetails[];
        Creadtedby: any;
     
        constructor() {
          this.quetionDeatils = new Array<DtQuestionDetails>();
        }
      }
     
      export class DtQuestionDetails {
        queid: any;
        QuestionText: any;
        QuestionDetailsId?: string;
        toolid: any;
        AnswerDetails: DTAnswerDetails[];
        CreatedBy: any;
     
        constructor() {
          this.AnswerDetails = new Array<DTAnswerDetails>();
        }
      }
     
      export class DTAnswerDetails {
        ansid: any;
        ansDetailsId: any;
        AnswerText: any;
     
        constructor() {}
      }
     

Comments

Popular posts from this blog

String Program in C#

CSV using XmlNode

Controller_Model. cs