File

src/app/modules/workspace/components/published-popup/published-popup.component.ts

Description

This component displays the checklist for publish content for reviewer and calls the Publish API to publish the content

Implements

OnInit

Metadata

Index

Properties
Methods

Constructor

constructor(route: Router, activatedRoute: ActivatedRoute, resourceService: ResourceService, toasterService: ToasterService, configService: ConfigService, routerNavigationService: RouterNavigationService, contentService: ContentService, userService: UserService, navigationHelperService: NavigationHelperService, workSpaceService: WorkSpaceService, reviewCommentsService: ReviewCommentsService)

Constructor to create injected service(s) object

Default method of RequestChangesPopupComponent class

Parameters :
Name Type Optional Description
route Router No

Reference of Router

activatedRoute ActivatedRoute No

Reference of ActivatedRoute

resourceService ResourceService No

Reference of ResourceService

toasterService ToasterService No

Reference of ToasterService

configService ConfigService No
routerNavigationService RouterNavigationService No
contentService ContentService No

Reference of contentService

userService UserService No

Reference of contentService

navigationHelperService NavigationHelperService No
workSpaceService WorkSpaceService No
reviewCommentsService ReviewCommentsService No

Methods

closeModalAfterError
closeModalAfterError()
Returns : void
createCheckedArray
createCheckedArray(checkedItem)

This method pushes all the checked reason into a array

Parameters :
Name Optional
checkedItem No
Returns : void
deleteReviewComments
deleteReviewComments()
Returns : void
getCheckListConfig
getCheckListConfig()
Returns : void
navigateToWorkspace
navigateToWorkspace()
Returns : void
ngOnInit
ngOnInit()

This method helps to get the user id from user service and content id from activated route

Returns : void
redirect
redirect()

Method to redirect to parent url

Returns : void
submitPublishChanges
submitPublishChanges()

This method builds the request body and call the publish API.

Returns : void
validateModal
validateModal()

This method checks whether the length of comments is greater than zero. It also checks whether a reject reason is checked. If both the validation is passed it enables the request changes button

Returns : void

Properties

Private activatedRoute
Type : ActivatedRoute

To send activatedRoute.snapshot to router navigation service for redirection to parent component

checkListData
Type : any

Checklist config

closeUrl
Type : any

To close url

comment
Type : string

Typed comment

Public configService
Type : ConfigService

To get url, app configs

contentId
Type : string

Content id which will be rejected

Public contentService
Type : ContentService

reference of ContentService.

inputFields
Decorators :
@ViewChildren('inputFields')
isDisabled
Default value : true

Flag to enable/disable request changes button

modal
Decorators :
@ViewChild('modal')
Public navigationHelperService
Type : NavigationHelperService
publishCheckListData
Type : any
reasons
Type : []
Default value : []

Checked reasons

Public resourceService
Type : ResourceService

To call resource service which helps to use language constant

Public reviewCommentsService
Type : ReviewCommentsService
route
Type : Router

To navigate to other pages

Public routerNavigationService
Type : RouterNavigationService

To navigate back to parent component

showDefaultConfig
Default value : false
showloader
Default value : true
showModal
Default value : false
Private toasterService
Type : ToasterService

To show toaster(error, success etc) after any API calls

totalItemCount
Type : Number

Total number of items on checklist

userId
Type : string

User id

Public userService
Type : UserService

To get user profile of logged-in user

Public workSpaceService
Type : WorkSpaceService
import { Component, OnInit, ViewChild, ViewChildren } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import * as _ from 'lodash-es';
import { ContentService, UserService } from '@sunbird/core';
import { ResourceService, ConfigService, ToasterService, ServerResponse,
  RouterNavigationService, NavigationHelperService } from '@sunbird/shared';
import { WorkSpaceService, ReviewCommentsService } from './../../services';

/**
 * This component displays the checklist for publish content for reviewer and
 * calls the Publish API to publish the content
 */
@Component({
  selector: 'app-published-popup',
  templateUrl: './published-popup.component.html'
})
export class PublishedPopupComponent implements OnInit {
  @ViewChild('modal') modal;
  @ViewChildren('inputFields') inputFields;
  /**
   * Total number of items on checklist
   */
  totalItemCount: Number;
  /**
   * User id
   */
  userId: string;
  /**
   * To navigate to other pages
   */
  route: Router;
  /**
   * Content id which will be rejected
   */
  contentId: string;
  /**
   * Typed comment
   */
  comment: string;
  /**
   * Checked reasons
   */
  reasons = [];
  /**
   * Flag to enable/disable request changes button
   */
  isDisabled = true;
  /**
   * To send activatedRoute.snapshot to router navigation
   * service for redirection to parent component
   */
  private activatedRoute: ActivatedRoute;
  /**
   * To call resource service which helps to use language constant
   */
  public resourceService: ResourceService;
  /**
   * To show toaster(error, success etc) after any API calls
   */
  private toasterService: ToasterService;
  /**
   * To navigate back to parent component
   */
  public routerNavigationService: RouterNavigationService;
  /**
   * To get url, app configs
   */
  public configService: ConfigService;
  /**
   * reference of ContentService.
   */
  public contentService: ContentService;
  /**
   * Checklist config
   */
  checkListData: any;
  /**
   * To close url
  */
  closeUrl: any;
  showDefaultConfig = false;
  showloader = true;
  publishCheckListData: any;
  showModal = false;
  /**
  * To get user profile of logged-in user
  */
  public userService: UserService;

 /**
	 * Constructor to create injected service(s) object
	 *
	 * Default method of RequestChangesPopupComponent class
	 *
   * @param {Router} route Reference of Router
   * @param {ActivatedRoute} activatedRoute Reference of ActivatedRoute
   * @param {ResourceService} resourceService Reference of ResourceService
   * @param {ToasterService} toasterService Reference of ToasterService
   * @param {ConfigService} config Reference of ConfigService
   * @param {ContentService} contentService Reference of contentService
   * @param {UserService} userService Reference of contentService
	 */
  constructor(route: Router,
    activatedRoute: ActivatedRoute,
    resourceService: ResourceService,
    toasterService: ToasterService,
    configService: ConfigService,
    routerNavigationService: RouterNavigationService,
    contentService: ContentService,
    userService: UserService,
    public navigationHelperService: NavigationHelperService,
    public workSpaceService: WorkSpaceService, public reviewCommentsService: ReviewCommentsService) {
    this.route = route;
    this.activatedRoute = activatedRoute;
    this.resourceService = resourceService;
    this.toasterService = toasterService;
    this.configService = configService;
    this.routerNavigationService = routerNavigationService;
    this.contentService = contentService;
    this.userService = userService;
    this.checkListData = this.configService.appConfig.CHECK_LIST_CONFIG;
  }

  /**
   * This method pushes all the checked reason into a array
   */
  createCheckedArray(checkedItem) {
    if (checkedItem && (_.indexOf(this.reasons, checkedItem) === -1)) {
      this.reasons.push(checkedItem);
    } else if (checkedItem && (_.indexOf(this.reasons, checkedItem) !== -1)) {
      this.reasons.splice(_.indexOf(this.reasons, checkedItem), 1);
    }
    this.validateModal();
  }

  /**
   * This method checks whether the length of comments is greater than zero.
   * It also checks whether a reject reason is checked.
   * If both the validation is passed it enables the request changes button
   */
  validateModal() {
    if ((this.inputFields && this.inputFields.length === this.reasons.length) || this.showDefaultConfig) {
      this.isDisabled = false;
    } else {
      this.isDisabled = true;
    }
  }

  /**
   * This method builds the request body and call the publish API.
   */
  submitPublishChanges() {
    this.isDisabled = true;
    const requestBody = {
      request: {
        content: {
          publishChecklist: this.reasons,
          lastPublishedBy: this.userId
        }
      }
    };
    const option = {
      url: `${this.configService.urlConFig.URLS.CONTENT.PUBLISH}/${this.contentId}`,
      data: requestBody
    };
    this.contentService.post(option).subscribe(response => {
      this.toasterService.success(this.resourceService.messages.smsg.m0004);
      this.modal.deny();
      this.deleteReviewComments();
    }, (err) => {
      this.toasterService.error(this.resourceService.messages.fmsg.m0019);
      this.modal.deny();
      this.redirect();
    });
  }
  navigateToWorkspace() {
    if (this.closeUrl.url.includes('flagreviewer')) {
      this.route.navigate(['workspace/content/flagreviewer/1']);
    } else {
      this.route.navigate(['workspace/content/upForReview/1']);
    }
  }
  deleteReviewComments() {
    if (this.contentId !== _.get(this.reviewCommentsService.contextDetails, 'contentId')) { // if stageId not fetched, throw error
      this.navigateToWorkspace();
      return ;
    }
    const requestBody = {
      request: {
        contextDetails: {
          contentId: _.get(this.reviewCommentsService.contextDetails, 'contentId'),
          contentVer: _.get(this.reviewCommentsService.contextDetails, 'contentVer'),
          contentType: _.get(this.reviewCommentsService.contextDetails, 'contentType')
        }
      }
    };
    this.reviewCommentsService.deleteComment(requestBody)
    .subscribe((res) => this.navigateToWorkspace(),
    (err) => this.navigateToWorkspace());
  }
  /**
   * Method to redirect to parent url
   */
  redirect() {
    this.route.navigate(['../'], {relativeTo: this.activatedRoute});
  }

  getCheckListConfig() {
    this.showDefaultConfig = false;
    const formServiceInputParams = {
      formType: 'content',
      formAction: 'publish',
      subType: 'resource'
    };
    this.workSpaceService.getFormData(formServiceInputParams).subscribe(
      (data: ServerResponse) => {
        if (data.result.form) {
          this.showModal = true;
          this.showloader = false;
          this.publishCheckListData = data.result.form.data.fields[0];
        } else {
          this.showModal = true;
          this.showloader = false;
          this.showDefaultConfig = true;
          this.validateModal();
        }
      },
      (err: ServerResponse) => {
        this.closeModalAfterError();
      }
    );
  }

  /**
   * This method helps to get the user id from user service and content id from activated route
   */
  ngOnInit() {
    this.userService.userData$.subscribe(userdata => {
      if (userdata && !userdata.err) {
        this.userId = userdata.userProfile.userId;
        this.activatedRoute.parent.params.subscribe((params) => {
          this.contentId = params.contentId;
          this.getCheckListConfig();
        });
      }
    });
    this.closeUrl = this.navigationHelperService.getPreviousUrl();
  }

  closeModalAfterError() {
    this.showModal = false;
    this.showloader = false;
    this.toasterService.error(this.resourceService.messages.emsg.m0005);
    this.redirect();
  }
}
<sui-modal
    [mustScroll]="true" 
    [isClosable]="false"
    [transitionDuration]="0"
    [size]="'normal'"
    class="sb-modal"
    appBodyScroll
    (dismissed)="redirect()" 
    #modal 
    *ngIf="showModal"
    >

    <i class="icon close" (click)="modal.deny('denied')" tabindex="0"></i>
    
    <!--Header-->
    <div class="sb-modal-header">
        {{resourceService.frmelmnts.btn.checkListPublish}}
    </div>
    <!--/Header-->

    <!--Content-->
    <div class="sb-modal-content">
        <div *ngIf="publishCheckListData">
            <div class="ui small header">
                <h4>{{publishCheckListData.title}}</h4>
            </div>
            <div class="ui three column grid">
                <div class="column" *ngFor="let list of publishCheckListData.contents">
                    <h5 class="ui tiny header">{{list.name}}</h5>
                    <div class="ui list" *ngFor="let item of list.checkList;">
                        <div class="item">
                            <div class="ui checkbox checklist">
                                <input type="checkbox" #inputFields class="listItem" tabindex="0" (click)="createCheckedArray(item)">
                                <label>{{item}}</label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div *ngIf="showDefaultConfig">
            <h5 class="ui small header">{{checkListData.publish.title}}</h5>
        </div>
        <div *ngIf="showloader">
            <app-loader></app-loader>
        </div>
    </div>
    <!--/Content-->

    <!--Actions-->
    <div class="sb-modal-actions">
        <button 
            class="sb-btn sb-btn-normal sb-btn-primary" 
            type="button" 
            [disabled]="isDisabled" 
            tabindex="0" (click)="submitPublishChanges()"
        >
            {{resourceService?.frmelmnts?.btn?.checklistPublish}}
        </button>
        <button 
            class="sb-btn sb-btn-normal sb-btn-outline-primary mr-8" 
            type="button" 
            tabindex="0" (click)="redirect();modal.deny();"
        >
            {{resourceService?.frmelmnts?.btn?.checklistCancel}}
        </button>
    </div>
    <!--/Actions-->
</sui-modal>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""