github.com/readium/readium-lcp-server@v0.0.0-20240101192032-6e95190e99f1/frontend/manage/app/purchase/purchase-list.component.ts (about)

     1  import { Component, OnInit }        from '@angular/core';
     2  import { Observable, Subscription } from 'rxjs/Rx';
     3  
     4  import { Slug }     from 'ng2-slugify';
     5  import * as moment  from 'moment';
     6  import * as saveAs  from 'file-saver';
     7  
     8  import { Purchase }          from './purchase';
     9  import { PurchaseService }   from './purchase.service';
    10  import { Publication }  from '../publication/publication';
    11  import { User }  from '../user/user';
    12  
    13  declare var Config: any; //  this comes from the autogenerated config.js file
    14  
    15  @Component({
    16      moduleId: module.id,
    17      selector: 'lcp-purchase-list',
    18      templateUrl: 'purchase-list.component.html'
    19  })
    20  
    21  export class PurchaseListComponent implements OnInit {
    22      purchases: Purchase[];
    23      search: string = "";
    24      order: string;
    25      reverse: boolean = false;
    26      private slug = new Slug('default');
    27  
    28      constructor(private purchaseService: PurchaseService) {
    29          this.purchases = [];
    30          this.order = "id";
    31          this.reverse = true;
    32      }
    33  
    34      refreshPurchases(): void {
    35          this.purchaseService.list().then(
    36              purchases => {
    37                  this.purchases = purchases;
    38              }
    39          );
    40      }
    41  
    42      orderBy(newOrder: string)
    43      {
    44        if (newOrder == this.order)
    45        {
    46          this.reverse = !this.reverse;
    47        }
    48        else
    49        {
    50          this.reverse = false;
    51          this.order = newOrder;
    52        }
    53      }
    54  
    55      keptWithFilter (pur: {publication: Publication, user: User}): boolean
    56      {
    57          if (pur.publication.title.toUpperCase().includes(this.search.toUpperCase()) || pur.user.name.toUpperCase().includes(this.search.toUpperCase()))
    58          {
    59              return true;
    60          }
    61  
    62          return false;
    63      }
    64  
    65      buildLicenseDeliveredClass(licenseUuid: string) {
    66           if (licenseUuid == null) {
    67              return "danger";
    68          }
    69  
    70          return "success";
    71      }
    72  
    73      buildStatusClass(status: string) {
    74          if (status == "error") {
    75              return "danger";
    76          } else if (status == "returned") {
    77              return "warning"
    78          }
    79          return "success";
    80      }
    81  
    82      formatDate(date: string): string {
    83          return moment(date).format('YYYY-MM-DD HH:mm');
    84      }
    85  
    86      ngOnInit(): void {
    87          this.refreshPurchases();
    88      }
    89  
    90      onRemove(objId: any): void {
    91          this.purchaseService.delete(objId).then(
    92              purchase => {
    93                  this.refreshPurchases();
    94              }
    95          );
    96      }
    97   }