How to use extractedBlocks method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

course-edit.component.ts

Source:course-edit.component.ts Github

copy

Full Screen

1import { Component, OnInit, SecurityContext } from '@angular/core';2import { Course } from '../../models/course.model';3import { ActivatedRoute, Router, NavigationEnd } from '@angular/router';4import { CourseService } from '../../services/course.service';5import { NgForm, FormGroup, FormControl, FormBuilder, FormArray, Validators } from '@angular/forms';6import { Section } from '../../models/section.model';7import { FileUploader } from 'ng2-file-upload';8import { Material } from '../../models/material.model';9import { Book } from '../../models/book.model';10import { MaterialService } from '../../services/material.service';11import { Globals } from '../../globals2';12import { MaterialCollection } from '../../models/materialcollection.model';13import { Materialtype } from '../../models/materialtype.model';14import { DomSanitizer } from '@angular/platform-browser';15import _ from 'lodash';16import {Location} from '@angular/common';17@Component({18 moduleId: module.id,19 templateUrl: 'course-edit.component.html',20 styleUrls: ['course-edit.component.css']21})22export class CourseEditComponent implements OnInit {23 courseFormGroup: FormGroup;24 sectionsFormArray: FormArray;25 sectionFormGroup: FormGroup;26 // materialFormArray: FormArray[];27 imageFormArray: FormArray[];28 bookFormArray: FormArray[];29 docFormArray: FormArray[];30 videoFormArray: FormArray[];31 audioFormArray: FormArray[];32 quoteFormArray: FormArray[];33 blockFormArray: FormArray[];34 sectionReferences: FormGroup[];35 materialReferences: FormArray[];36 course: Course;37 id: string;38 errorMessage: string;39 image: string;40 imageUrl = '';41 public uploader: FileUploader;42 localImageUrl = '';43 tempName = '';44 thisFile: File;45 allpossiblematerials: Material[];46 docs: Material[];47 books: Material[];48 videos: Material[];49 audios: Material[];50 // extractedBooks: Material[][];51 // extractedDocs: Material[][];52 // extractedVideos: Material[][];53 // extractedAudios: Material[][];54 // extractedQuotes: Material[][];55 // extractedBlocks: Material[][];56 // extractedImages: Material[][];57 bookOptions: Material[];58 docOptions: Material[];59 videoOptions: Material[];60 audioOptions: Material[];61 quoteOptions: Material[];62 blockOptions: Material[];63 imageOptions: Material[];64 matObjRefArray: Object[];65 existingImage: string;66 uploadedCourseImage: boolean;67 materialFormArrayReferences: FormArray[]; // these are just pointers to the various material form arrays68 materialPlaceholder: string;69 bookPlaceholder: string;70 videoPlaceholder: string;71 docPlaceholder: string;72 audioPlaceholder: string;73 blockPlaceholder: string;74 quotePlaceholder: string;75 imagePlaceholder: string;76 materialTypes: Materialtype[];77 sectionMaterials: MaterialCollection[]; // this is an array of the actual Material Objects that are being78 // referenced by the section(s) -- haven't implemented this yet.79 constructor(private router: Router, private activated_route: ActivatedRoute,80 private courseService: CourseService, private fb: FormBuilder,81 private materialService: MaterialService, private globals: Globals,82 private _sanitizer: DomSanitizer,83 private _location: Location ) { }84 ngOnInit(): void {85 this.materialTypes = this.globals.materialTypes;86 this.materialPlaceholder = 'Choose a Material';87 this.bookPlaceholder = 'Choose a Book Reference';88 this.docPlaceholder = 'Choose a PDF Document';89 this.audioPlaceholder = 'Choose an audio file';90 this.videoPlaceholder = 'Choose a video file';91 this.quotePlaceholder = 'Choose a quote';92 this.blockPlaceholder = 'Choose a block';93 this.imagePlaceholder = 'Choose an image';94 this.courseService.ngOnInit();95 // this.extractedBooks = [];96 // this.extractedDocs = [];97 // this.extractedVideos = [];98 // this.extractedAudios = [];99 // this.extractedQuotes = [];100 // this.extractedBlocks = [];101 // this.extractedImages = [];102 this.imageFormArray = [];103 this.bookFormArray = [];104 this.docFormArray = [];105 this.videoFormArray = [];106 this.audioFormArray = [];107 this.quoteFormArray = [];108 this.blockFormArray = [];109 // Get the id from the activated route -- and get the data from the resolvers110 this.id = this.activated_route.snapshot.params['id'];111 // console.log('About to Edit Course ID: ' + this.id);112 this.course = this.activated_route.snapshot.data['course'];113 // console.log('Course: ' + JSON.stringify(this.course));114 this.allpossiblematerials = this.activated_route.snapshot.data['materials'];115 if (this.id !== '0' && ( this.course.image !== '' )) {116 this.existingImage = this.globals.courseimages + '/' + this.id + '/' + this.course.image;117 // console.log('Existing image: ' + this.existingImage);118 }119 // console.log(JSON.stringify(this.materials));120 this.uploadedCourseImage = false;121 this.sectionsFormArray = this.fb.array([ ]);122 this.courseFormGroup = this.fb.group({123 title: [ '', [Validators.required, Validators.minLength(3)] ] ,124 description: [ '', [Validators.required ]],125 imageUploader: '',126 sections: this.sectionsFormArray127 });128 // console.log('Built course form');129 this.getPossibleImages();130 this.getPossibleVideos();131 this.getPossibleBooks();132 this.getPossibleDocs();133 this.getPossibleAudios();134 this.getPossibleQuotes();135 this.getPossibleBlocks();136 // console.log('gotDocs');137 this.addCourseImage();138 this.deLintMe();139 this.buildSections();140 }141 buildNewSection(i) {142 this.extractStuff(i);143 this.imageFormArray[i] = this.fb.array([]);144 this.bookFormArray[i] = this.fb.array([]);145 this.docFormArray[i] = this.fb.array([]);146 this.videoFormArray[i] = this.fb.array([]);147 this.audioFormArray[i] = this.fb.array([]);148 this.quoteFormArray[i] = this.fb.array([]);149 this.blockFormArray[i] = this.fb.array([]);150 // if (!this.course.sections[i]) {151 // this.course.sections[i] = new Section('', '', '', null, null, i);152 // }153 // if (this.course.sections[i] && this.extractedImages[i] ) {154 // for (let j = 0; j < this.extractedImages[i].length; j++ ) {155 // this.imageFormArray[i].push(this.buildMaterialsSubSection(this.extractedImages[i][j]['id'] ));156 // } }157 // if (this.course.sections[i] && this.extractedVideos[i] ) {158 // for (let j = 0; j < this.extractedVideos[i].length; j++ ) {159 // this.videoFormArray[i].push(this.buildMaterialsSubSection(this.extractedVideos[i][j]['id'] ));160 // } }161 // if (this.course.sections[i] && this.extractedAudios[i] ) {162 // for (let j = 0; j < this.extractedAudios[i].length; j++ ) {163 // this.audioFormArray[i].push(this.buildMaterialsSubSection(this.extractedAudios[i][j]['id'] ));164 // } }165 // if (this.course.sections[i] && this.extractedBooks[i] ) {166 // for (let j = 0; j < this.extractedBooks[i].length; j++ ) {167 // this.bookFormArray[i].push(this.buildMaterialsSubSection(this.extractedBooks[i][j]['id'] ));168 // } }169 // if (this.course.sections[i] && this.extractedDocs[i] ) {170 // for (let j = 0; j < this.extractedDocs[i].length; j++ ) {171 // this.docFormArray[i].push(this.buildMaterialsSubSection(this.extractedDocs[i][j]['id']) );172 // } }173 // if (this.course.sections[i] && this.extractedQuotes[i] ) {174 // for (let j = 0; j < this.extractedQuotes[i].length; j++ ) {175 // this.quoteFormArray[i].push(this.buildMaterialsSubSection(this.extractedQuotes[i][j]['id']) );176 // } }177 // if (this.course.sections[i] && this.extractedBlocks[i] ) {178 // for (let j = 0; j < this.extractedBlocks[i].length; j++ ) {179 // this.blockFormArray[i].push(this.buildMaterialsSubSection(this.extractedBlocks[i][j]['id']) );180 // } }181 // this.sectionMaterials[i] = this.materialService.sortMaterials(this.course.sections[i].materials);182 let title = '';183 let content = '';184 if (this.course.sections[i]) {185 if (this.course.sections[i].title) { title = this.course.sections[i].title; }186 if (this.course.sections[i].content) { content = this.course.sections[i].content; }187 }188 this.sectionReferences[i] = this.fb.group( {189 title: title,190 content: content,191 // materials: this.materialFormArray[i],192 images: this.imageFormArray[i],193 videos: this.videoFormArray[i],194 audios: this.audioFormArray[i],195 books: this.bookFormArray[i],196 docs: this.docFormArray[i],197 quotes: this.quoteFormArray[i],198 blocks: this.blockFormArray[i]199 });200 this.sectionsFormArray.push( this.sectionReferences[i] );201 }202 buildSections() {203 // console.log('building sections.');204 this.sectionReferences = [];205 // this.materialFormArray = [];206 this.imageFormArray = [];207 this.bookFormArray = [];208 this.docFormArray = [];209 this.videoFormArray = [];210 this.audioFormArray = [];211 this.quoteFormArray = [];212 this.blockFormArray = [];213 for (let i = 0; i < this.course.sections.length; i++) {214 this.buildNewSection(i);215 }216 this.populateForm();217 }218 get sections(): FormArray {219 return <FormArray>this.courseFormGroup.get('sections');220 }221 buildSection(): FormGroup {222 return this.fb.group( {223 title: '',224 content: '',225 images: [],226 videos: [],227 audios: [],228 books: [],229 docs: [],230 quotes: [],231 blocks: []232 });233 }234 buildMaterialsSubSection(value) {235 return this.fb.group({236 material: value237 });238 }239 extract( sectionNumber, type) {240 const extractedArray = [];241 if (this.course && this.course.sections &&242 this.course.sections[sectionNumber] &&243 this.course.sections[sectionNumber].materials) {244 for ( let j = 0; j < this.course.sections[sectionNumber].materials.length; j++) {245 const matID = this.course.sections[sectionNumber].materials[j];246 // console.log('mat: ' + JSON.stringify(matObj));247 if (matID) {248 const foundObj = this.allpossiblematerials.find( materialObject => (materialObject.id === matID ) );249 if (foundObj) {250 // console.log( ' Found: ' + JSON.stringify(foundObj));251 if (foundObj['type'] === type) {252 extractedArray.push(foundObj);253 }254 }255 }256 }257 }258 // console.log('my extracted Array: ' + JSON.stringify(extractedArray));259 return extractedArray;260 }261 // We want an array of books that has been selected for this SECTION --262 // so we look through all of the materials for this section, and extract the ones that are 'books'263 extractStuff(sectionNumber) {264 // const offSetSectionNumber = sectionNumber + 1;265 // this.extractedImages[sectionNumber] = [];266 // this.extractedImages[sectionNumber] = this.extract(sectionNumber, 'image');267 // this.extractedBooks[sectionNumber] = [];268 // this.extractedBooks[sectionNumber] = this.extract(sectionNumber, 'book');269 // this.extractedDocs[sectionNumber] = [];270 // this.extractedDocs[sectionNumber] = this.extract(sectionNumber, 'doc');271 // this.extractedVideos[sectionNumber] = [];272 // this.extractedVideos[sectionNumber] = this.extract(sectionNumber, 'video');273 // this.extractedAudios[sectionNumber] = [];274 // this.extractedAudios[sectionNumber] = this.extract(sectionNumber, 'audio');275 // this.extractedQuotes[sectionNumber] = [];276 // this.extractedQuotes[sectionNumber] = this.extract(sectionNumber, 'quote');277 // this.extractedBlocks[sectionNumber] = [];278 // this.extractedBlocks[sectionNumber] = this.extract(sectionNumber, 'block');279 }280 fileChange(event) {281 const fileList: FileList = event.target.files;282 if ( fileList.length > 0) {283 const file: File = fileList[0];284 this.thisFile = file;285 }286 }287 populateForm(): void {288 this.courseFormGroup.patchValue({'title': this.course.title,289 'description': this.course.description });290 }291 deLintMe() {292 for (let i = 0; i < this.course.sections.length; i++) {293 // console.log('delinting the sections');294 const sc = this.course.sections[i].content;295 if (sc) {296 const editedSC = sc.replace(/<br>/g, '\n');297 this.course.sections[i].content = editedSC; }298 }299 }300 lintMe( combinedCourseObject ) {301 let lintedModel = combinedCourseObject;302 // console.log('LINTING: ');303 for (let i = 0; i < combinedCourseObject.sections.length; i++) {304 // console.log('Linting section: ' + i);305 const sectionContent = combinedCourseObject.sections[i].content;306 let LintedSectionContent = sectionContent;307 if (sectionContent) {308 LintedSectionContent = sectionContent.replace(/\n/g, '<br>'); }309 combinedCourseObject.sections[i].content = LintedSectionContent;310 // console.log(combinedCourseObject.sections[i].content);311 }312 lintedModel = combinedCourseObject;313 return lintedModel;314 }315 postCourse() {316 if (this.uploadedCourseImage) {317 this.course.image = this.image; }318 // This is Deborah Korata's way of merging our data model with the form model319 let combinedCourseObject = Object.assign( {}, this.course, this.courseFormGroup.value);320 // const combinedCourseObject = this.courseFormGroup.value;321 // add a dummy "section Zero" to the front of the sections array -- (which we use as the course syllabus page)322 // combinedCourseObject.sections.unshift({ 'sectionNumber' : '0' });323 // I want to consolidate all the materials into one array for each section324 for (let j = 0; j < combinedCourseObject.sections.length; j++) {325 combinedCourseObject.sections[j].materials = [];326 const audioGroup = combinedCourseObject.sections[j].audios;327 combinedCourseObject.sections[j].materials = combinedCourseObject.sections[j].materials.concat(audioGroup);328 const videoGroup = combinedCourseObject.sections[j].videos;329 combinedCourseObject.sections[j].materials = combinedCourseObject.sections[j].materials.concat(videoGroup);330 delete combinedCourseObject.sections[j].videos;331 const bookGroup = combinedCourseObject.sections[j].books;332 combinedCourseObject.sections[j].materials = combinedCourseObject.sections[j].materials.concat(bookGroup);333 delete combinedCourseObject.sections[j].books;334 const docGroup = combinedCourseObject.sections[j].docs;335 combinedCourseObject.sections[j].materials = combinedCourseObject.sections[j].materials.concat(docGroup);336 delete combinedCourseObject.sections[j].docs;337 const quoteGroup = combinedCourseObject.sections[j].quotes;338 combinedCourseObject.sections[j].materials = combinedCourseObject.sections[j].materials.concat(quoteGroup);339 delete combinedCourseObject.sections[j].quotes;340 const blockGroup = combinedCourseObject.sections[j].blocks;341 combinedCourseObject.sections[j].materials = combinedCourseObject.sections[j].materials.concat(blockGroup);342 delete combinedCourseObject.sections[j].blocks;343 const imageGroup = combinedCourseObject.sections[j].images;344 combinedCourseObject.sections[j].materials = combinedCourseObject.sections[j].materials.concat(imageGroup);345 delete combinedCourseObject.sections[j].audios;346 delete combinedCourseObject.sections[j].videos;347 delete combinedCourseObject.sections[j].books;348 delete combinedCourseObject.sections[j].docs;349 delete combinedCourseObject.sections[j].quotes;350 delete combinedCourseObject.sections[j].blocks;351 delete combinedCourseObject.sections[j].images;352 // I also want to strip out the individual objects and just store an array of ID #s.353 if (combinedCourseObject.sections[j].materials) {354 const IDArray = combinedCourseObject.sections[j].materials.map( material => {355 if (material && material.material) {356 return material.material; } else { return null; }357 });358 combinedCourseObject.sections[j].materials = IDArray;359 }360 // we also need to store the SectionNumber -- although this might eventually already be part of the model361 // after / if we add the ability to move sections around. For now - we'll just store the index.362 combinedCourseObject.sections[j].sectionNumber = j;363 // console.log('Section' + j + ': ' + JSON.stringify(combinedCourseObject.sections[j]) );364 }365 // console.log( 'Posting course: ' + JSON.stringify(combinedCourseObject) );366 const lintedModel = this.lintMe( combinedCourseObject );367 combinedCourseObject = lintedModel;368 combinedCourseObject.sections[0] = { 'sectionNumber': 0 };369 combinedCourseObject.sections[0].materials = [];370 if (this.course.id === '0') {371 this.courseService.createCourse( combinedCourseObject ).subscribe(372 (val) => {373 },374 response => { this.reset();375 this.router.navigate(['/admin/classes']);376 },377 () => {378 this.reset();379 this.router.navigate(['/admin/classes']);380 }381 );382 } else {383 // Validate stuff here384 this.courseService385 .updateCourse( combinedCourseObject ).subscribe(386 (val) => {387 },388 response => { this.reset(); this.router.navigate(['/admin/classes']);389 },390 () => {391 this.reset();392 this.router.navigate(['/admin/classes']);393 }394 );395 }396 }397 reset() {398 this.courseFormGroup.reset();399 }400 getPossibleQuotes() {401 this.materialService.getDynamicMaterials(0, 'quote').subscribe(402 quotes => { this.quoteOptions = this.sortObjs(quotes); },403 error => this.errorMessage = <any> error);404 }405 getPossibleImages() {406 this.materialService.getDynamicMaterials(0, 'image').subscribe(407 images => { this.imageOptions = this.sortObjs(images); },408 error => this.errorMessage = <any> error);409 }410 getPossibleVideos() {411 this.materialService.getDynamicMaterials(0, 'video').subscribe(412 videos => { this.videoOptions = this.sortObjs(videos); },413 error => this.errorMessage = <any> error);414 }415 getPossibleAudios() {416 this.materialService.getDynamicMaterials(0, 'audio').subscribe(417 audios => { this.audioOptions = this.sortObjs(audios); },418 error => this.errorMessage = <any> error);419 }420 getPossibleBooks() {421 this.materialService.getDynamicMaterials(0, 'book').subscribe(422 books => {423 this.bookOptions = this.sortObjs(books);424 },425 error => this.errorMessage = <any> error);426 }427 getPossibleBlocks() {428 this.materialService.getDynamicMaterials(0, 'block').subscribe(429 blocks => {430 this.blockOptions = this.sortObjs(blocks);431 },432 error => this.errorMessage = <any> error);433 }434 getPossibleDocs() {435 this.materialService.getDynamicMaterials(0, 'doc').subscribe(436 docs => {437 this.docOptions = this.sortObjs(docs);438 console.log('possible docs: ');439 this.docOptions.map( doc => console.log(doc.title));440 },441 error => this.errorMessage = <any> error);442 }443 sortObjs( objs) {444 const sortedObjs = _.sortBy(objs, item => item.title);445 return sortedObjs;446 }447 addSection(): void {448 let newSection = 1;449 if (this.course.sections && this.course.sections.length > 0) {450 console.log('At least one section already exists.');451 newSection = this.course.sections.length;452 this.course.sections.push(new Section( '', '', [], null, newSection) );453 console.log('About to build a new section:' + newSection);454 this.buildNewSection(newSection);455 } else {456 newSection = 0;457 this.course.sections.push(new Section( '', '', [], null, newSection) );458 this.buildNewSection(0);459 newSection = 1;460 this.course.sections.push(new Section( '', '', [], null, newSection) );461 this.buildNewSection(1);462 }463 }464 addQuote(i): void {465 if (this.quoteFormArray[i]) {466 this.quoteFormArray[i].push(this.buildMaterialsSubSection(''));467 } else {468 this.quoteFormArray[i] = this.fb.array([]);469 this.quoteFormArray[i].push(this.buildMaterialsSubSection(''));470 }471 }472 addImage(i): void {473 if (this.imageFormArray[i]) {474 this.imageFormArray[i].push(this.buildMaterialsSubSection(''));475 } else {476 this.imageFormArray[i] = this.fb.array([]);477 this.imageFormArray[i].push(this.buildMaterialsSubSection(''));478 }479 }480 addVideo(i): void {481 if (this.videoFormArray[i]) {482 this.videoFormArray[i].push(this.buildMaterialsSubSection(''));483 } else {484 this.videoFormArray[i] = this.fb.array([]);485 this.videoFormArray[i].push(this.buildMaterialsSubSection(''));486 }487 }488 addAudio(i): void {489 if (this.audioFormArray[i]) {490 this.audioFormArray[i].push(this.buildMaterialsSubSection(''));491 } else {492 this.audioFormArray[i] = this.fb.array([]);493 this.audioFormArray[i].push(this.buildMaterialsSubSection(''));494 }495 }496 addBlock(i): void {497 if (this.blockFormArray[i]) {498 this.blockFormArray[i].push(this.buildMaterialsSubSection(''));499 } else {500 this.blockFormArray[i] = this.fb.array([]);501 this.blockFormArray[i].push(this.buildMaterialsSubSection(''));502 }503 }504 addBook(i): void {505 // console.log('Adding Book to section: ' + i);506 if (this.bookFormArray[i]) {507 console.log('FormArray for section #' + i + ' exists.');508 this.bookFormArray[i].push(this.buildMaterialsSubSection(''));509 } else {510 console.log('Creating FormArray for section #' + i);511 this.bookFormArray[i] = this.fb.array([]);512 this.bookFormArray[i].push(this.buildMaterialsSubSection(''));513 }514 // console.log('Done building bookFormArray');515 }516 addDoc(i): void {517 // console.log('Adding PDF Document to section: ' + i);518 if (this.docFormArray[i]) {519 console.log('FormArray for section #' + i + ' exists.');520 this.docFormArray[i].push(this.buildMaterialsSubSection(''));521 } else {522 console.log('Creating FormArray for section #' + i);523 this.docFormArray[i] = this.fb.array([]);524 this.docFormArray[i].push(this.buildMaterialsSubSection(''));525 }526 // console.log('Done building bookFormArray');527 }528 killSection(i) {529 const k = confirm('Are you sure you want to delete this whole section, and all the related reference materials?');530 if (k) {531 this.sections.removeAt(i); }532 }533 // killBook(i, k) {534 // this.bookFormArray[i].removeAt(k);535 // }536 // killBlock(i, k) {537 // this.blockFormArray[i].removeAt(k);538 // }539 // killImage(i, k) {540 // this.imageFormArray[i].removeAt(k);541 // }542 // killDoc(i, k) {543 // this.docFormArray[i].removeAt(k);544 // }545 // killVideo(i, k) {546 // this.videoFormArray[i].removeAt(k);547 // }548 // killQuote(i, k) {549 // this.quoteFormArray[i].removeAt(k);550 // }551 // killAudio(i, k) {552 // this.audioFormArray[i].removeAt(k);553 // }554 addCourseImage() {555 console.log('adding course image');556 const urlWithQuery = this.globals.postcourseimages + '?id=' + this.id;557 this.uploader = new FileUploader({url: urlWithQuery});558 this.uploader.onAfterAddingFile = (fileItem) => {559 const url = (window.URL) ? window.URL.createObjectURL(fileItem._file)560 : (window as any).webkitURL.createObjectURL(fileItem._file);561 this.localImageUrl = url;562 this.uploader.queue[0].upload();563 this.uploadedCourseImage = true;564 };565 this.uploader.onCompleteItem = (item: any, response: any, status: any, headers: any) => {566 this.tempName = this.uploader.queue[0].file.name;567 this.image = this.tempName;568 this.imageUrl = this.globals.courseimages + '/' +569 this.course.id + '/' + this.image;570 this.uploader.queue[0].remove();571 };572 }573 escapeHtml(unsafe) {574 return unsafe.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')575 .replace(/"/g, '&quot;').replace(/'/g, '&#039;');576 }577 moveUp(i) {578 if (i > 1) {579 console.log('moving up: ' + i);580 // const dummySection = this.sectionReferences[i - 1];581 // const dummyFormArray = this.sectionsFormArray[i - 1];582 // this.sectionReferences[i - 1] = this.sectionReferences[i];583 // this.sectionsFormArray[i - 1] = this.sectionsFormArray[i];584 // this.sectionReferences[i] = dummySection;585 // this.sectionsFormArray[i] = dummyFormArray;586 // this.courseFormGroup.patchValue({sections: this.sectionsFormArray });587 }588 }589 closer() {590 this.router.navigate(['/admin/classes']);591 // this._location.back();592 // // this.router.navigate(['/coursebuilder']);593 }594 removeCourse() {595 this.courseService.removeCourse( this.course).subscribe( (val) => {596 this.router.navigate(['/admin/classes']);597 }, response => { this.router.navigate(['/admin/classes']); },598 () => { this.router.navigate(['/admin/classes']); });599 }600 deleteCourse(courseId) {601 const result = confirm( 'Are you sure you want to delete this course,' +602 ' and All of it\'s related sections, width ID: ' + courseId + '? ');603 if (result) {604 console.log('Got the ok to delete the course.');605 this.courseService.deleteCourse(courseId).subscribe(606 (data) => {607 console.log('Got back from the Course Service.');608 this.router.navigate(['/coursebuilder']);609 },610 error => {611 this.errorMessage = <any>error;612 // This is a work-around for a HTTP error message I was getting even when the613 // course was successfully deleted.614 if (error.status === 200) {615 console.log('Got back from the Course Service.');616 this.router.navigate(['/coursebuilder']);617 } else {618 console.log('Error: ' + JSON.stringify(error) ); }619 } );620 }621 }...

Full Screen

Full Screen

task.js

Source:task.js Github

copy

Full Screen

1var c2stem = new C2Stem();2c2stem.fixupLogoutLink();3$( window ).on( "load", function() {4 console.log( "ready!" );5 c2stem.loadTaskData(c2stem.query.id, function (err, res) {6 if(res === null){7 // c2stem.logout(function (err) {8 window.location.href = "login.html";9 // });10 return;11 }12 console.log("loading task",res.id);13 c2stem.task_id = res.id;14 c2stem.module_id = res.parent.id;15 c2stem.mode = c2stem.query.mode;16 TaskViewActionManger.pageLoaded(c2stem.task_id, c2stem.module_id);17 if(c2stem.mode !== null && (c2stem.mode === 'teacher' ))18 $('#reset_to_template').hide();19 c2stem.getUserRole(function () {20 if(c2stem.userRole.role !== 'teacher' && c2stem.mode === 'teacher'){21 c2stem.mode = "";22 }23 $("#dashboard").hide();24 if(c2stem.userRole.role === "teacher" || c2stem.userRole.role !== 'researcher'){25 $("#dashboard").show();26 }27 console.log()28 c2stem.isNewTask(function () {29 console.log("isNewTask:", c2stem.isNewTask);30 c2stem.loadPublicProject(c2stem.task_id, null, false, function (err) {31 loadTask(err,res);32 });33 });34 });35 });36});37function loadTask(err, res) {38 if (err === "ERROR: Not logged in") {39 window.location.href = "login.html";40 } else if (err && err !== "ERROR: Project not found" ) {41 Materialize.toast(err || 'Could not load tasks');42 } else {43 console.log("c2stem.userTaskData:", c2stem.userTaskData);44 c2stem.fixupModuleLink(res.parent.id, res.parent.name);45 c2stem.fixupTaskLink(res.id, res.name);46 $('#tabs-div').append('<ul class="tabs tabs-transparent"></ul>');47 var tab = null;48 for (var i = 0; i < res.tabs.length; i++) {49 tab = res.tabs[i];50 $("#tabs-div ul").append(`<li class="tab"><a href="#tab${tab.id}" id="tab_${tab.id}">${tab.name}</a></li>`)51 if (tab.type === 'desc') {52 c2stem.addDescriptionTab(tab.id, tab.name, tab.markup);53 } else if (tab.type === 'snap1') {54 c2stem.addSnap1Tab(tab.id, tab.name, tab.template);55 } else if (tab.type === 'snap2') {56 c2stem.addSnap2Tab(tab.id, tab.name);57 } else if (tab.type === 'cm') {58 c2stem.addConcpetualModelingTab(tab.id, tab.name, tab.data);59 }60 var n = document.getElementById("tab_"+tab.id);61 n.tab_name = tab.name;62 n.tab_type = tab.type;63 $("#tab_"+tab.id).click(function (event) {64 var eid = event.currentTarget.id;65 var n = document.getElementById(eid);66 // console.log("tab clicked:", n.tab_name, n.tab_type);67 TaskViewActionManger.switchTab(n.tab_name, n.tab_type);68 // ConceptualActionManager.deleteProperty(selected_concept, selected_property);69 });70 }71 $("#reset_to_template").click(function () {72 var cloud = C2StemCloud;73 TaskViewActionManger.resetTask(c2stem.task_id, c2stem.module_id);74 cloud.deleteUserProgress(c2stem.task_id, function () {75 console.log(c2stem.task_id," reset_to_template successful");76 location.reload();77 }, function (err) {78 console.log(c2stem.task_id,"could not reset_to_template, err:", err);79 });80 });81 $("#logout").click(function () {82 LoginActionManger.logout();83 });84 // $("#ExportSnapBlocks").click(function () {85 // c2stem.SaveBlocksCache("ExtractedBlocks", function (error) {86 // if(error === null){87 // c2stem.loadBlocksCache("ExtractedBlocks", "d.asif.hasan");88 // }89 // });90 // });91 $('ul.tabs').tabs(); // visualize the tabs92 }...

Full Screen

Full Screen

BlockParser.ts

Source:BlockParser.ts Github

copy

Full Screen

1import * as winston from "winston";2import { Block } from "../models/BlockModel";3import { IBlock } from "./CommonInterfaces";4import { Sdk } from "../services/Sdk";5import { MissedBlock } from "../models/MissedBlockModel";6import { Config } from "./Config";7import * as Bluebird from "bluebird";8const config = require("config");9export class BlockParser {10 public async parseBlocks(blocks: any) {11 if (blocks.length === 0) return Promise.resolve();12 const extractedBlocks = blocks.flatMap((block: any) => {13 return new Block(this.extractBlockData(block));14 });15 const bulkBlocks = Block.collection.initializeUnorderedBulkOp();16 extractedBlocks.forEach((block: IBlock) => {17 bulkBlocks18 .find({ height: block.height })19 .upsert()20 .replaceOne(block);21 });22 if (bulkBlocks.length === 0) return Promise.resolve();23 return bulkBlocks.execute().then((bulkResult: any) => {24 return Promise.resolve(extractedBlocks);25 });26 }27 extractBlockData(block: any) {28 return {29 height: Number(block.block_meta.header.height),30 hash: String(block.block_meta.block_id.hash),31 time: block.block_meta.header.time,32 num_txs: Number(block.block_meta.header.num_txs),33 proposer: String(block.block_meta.header.proposer_address)34 };35 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const {extractedBlocks} = require('fast-check-monorepo');2const f = (a, b) => a + b;3const g = (a, b) => a - b;4const h = (a, b) => a * b;5const blocks = extractedBlocks([f, g, h]);6console.log(blocks);7const {extractedBlocks} = require('fast-check-monorepo');8const f = (a, b) => a + b;9const g = (a, b) => a - b;10const h = (a, b) => a * b;11const blocks = extractedBlocks([f, g, h]);12console.log(blocks);13const {extractedBlocks} = require('fast-check-monorepo');14const f = (a, b) => a + b;15const g = (a, b) => a - b;16const h = (a, b) => a * b;17const blocks = extractedBlocks([f, g, h]);18console.log(blocks);19const {extractedBlocks} = require('fast-check-monorepo');20const f = (a, b) => a + b;21const g = (a, b) => a - b;22const h = (a, b) => a * b;23const blocks = extractedBlocks([f, g, h]);24console.log(blocks);25const {extractedBlocks} = require('fast-check-monorepo');26const f = (a, b) => a + b;27const g = (a, b) => a - b;28const h = (a, b) => a * b;

Full Screen

Using AI Code Generation

copy

Full Screen

1const {extractedBlocks} = require('fast-check');2extractedBlocks(1, 2, 3);3console.log('test3');4const {extractedBlocks} = require('fast-check');5extractedBlocks(1, 2, 3);6console.log('test4');7const {extractedBlocks} = require('fast-check');8extractedBlocks(1, 2, 3);9console.log('test5');10const {extractedBlocks} = require('fast-check');11extractedBlocks(1, 2, 3);12console.log('test6');13const {extractedBlocks} = require('fast-check');14extractedBlocks(1, 2, 3);15console.log('test7');16const {extractedBlocks} = require('fast-check');17extractedBlocks(1, 2, 3);18console.log('test8');19const {extractedBlocks} = require('fast-check');20extractedBlocks(1, 2, 3);21console.log('test9');22const {extractedBlocks} = require('fast-check');23extractedBlocks(1, 2, 3);24console.log('test10');25const {extractedBlocks} = require('fast-check');26extractedBlocks(1, 2, 3);27console.log('test11');28const {extractedBlocks} = require('fast-check');29extractedBlocks(1, 2, 3);30console.log('test12');

Full Screen

Using AI Code Generation

copy

Full Screen

1const {extractedBlocks} = require('@fast-check/arbitrary/ExtractedBlocks.js');2const {fc} = require('@fast-check/arbitrary/ExtractedBlocks.js');3const {extractedBlocks} = require('@fast-check/arbitrary/ExtractedBlocks.js');4const {fc} = require('@fast-check/arbitrary/ExtractedBlocks.js');5fc.assert(6 fc.property(fc.integer(), fc.integer(), (a, b) => {7 return a + b === b + a;8 })9);10fc.assert(11 fc.property(fc.integer(), fc.integer(), (a, b) => {12 return a * b === b * a;13 })14);15fc.assert(16 fc.property(fc.integer(), fc.integer(), (a, b) => {17 return a - b === -(b - a);18 })19);20fc.assert(21 fc.property(fc.integer(), fc.integer(), (a, b) => {22 return a / b === 1 / (b / a);23 })24);25fc.assert(26 fc.property(fc.integer(), fc.integer(), (a, b) => {27 return a % b === a - Math.floor(a / b) * b;28 })29);30fc.assert(31 fc.property(fc.integer(), fc.integer(), (a, b) => {32 return a ** b === Math.pow(a, b);33 })34);35fc.assert(36 fc.property(fc.integer(), fc.integer(), (a, b) => {37 return a & b === b & a;38 })39);40fc.assert(41 fc.property(fc.integer(), fc.integer(), (a, b) => {42 return a | b === b | a;43 })44);45fc.assert(46 fc.property(fc.integer(), fc.integer(), (a, b) => {47 return a ^ b === b ^ a;48 })49);50fc.assert(51 fc.property(fc.integer(), fc.integer(), (a, b) => {52 return a << b === b << a;53 })54);55fc.assert(56 fc.property(fc.integer(), fc.integer(), (a, b) => {57 return a >> b === b >> a;58 })59);60fc.assert(61 fc.property(fc.integer(), fc.integer(), (a, b) => {62 return a >>> b === b >>> a;63 })64);65fc.assert(66 fc.property(fc.integer(), fc.integer(), (a, b) => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const {extractedBlocks} = require('fast-check-monorepo');3fc.configureGlobal({numRuns: 1000});4const arb = fc.integer(-100, 100);5const isOdd = (n) => n % 2 !== 0;6const isEven = (n) => n % 2 === 0;7describe('isOdd', () => {8 extractedBlocks(arb, isOdd, {9 });10});11describe('isEven', () => {12 extractedBlocks(arb, isEven, {13 });14});15 ✓ should hold for all the examples (3ms)16 ✓ should hold for all the generated values (3ms)17 ✓ should hold for all the examples (2ms)18 ✓ should hold for all the generated values (2ms)19 ✓ should hold for all the examples (2ms)20 ✓ should hold for all the examples (1ms)

Full Screen

Using AI Code Generation

copy

Full Screen

1const {extractedBlocks} = require('fast-check');2const mySpec = {3 {4 {5 {6 {7 {8 {9 {10 {11 {12 {13 {14 {15 {16 {17 {18 {19 {20 {21 {22 {23 {24 {25 {26 {27 {28 {29 {30 {31 {32 {

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { extractedBlocks } = require('fast-check-monorepo');3 .integer()4 .noBias()5 .noShrink();6 .integer()7 .noBias()8 .noShrink();9 .integer()10 .noBias()11 .noShrink();12 .integer()13 .noBias()14 .noShrink();15 .integer()16 .noBias()17 .noShrink();18 .integer()19 .noBias()20 .noShrink();21const arbitraries = [arb, arb2, arb3, arb4, arb5, arb6];22const sizes = [1, 2, 3, 4, 5, 6];23const frequencies = [1, 2, 3, 4, 5, 6];24const seeds = [1, 2, 3, 4, 5, 6];25const results = extractedBlocks(arbitraries, sizes, frequencies, seeds);26console.log(results);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful