You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
1.9 KiB

  1. export class ExampleItemList {
  2. constructor(
  3. private _count: number,
  4. private _next: string | null,
  5. private _prev: string | null,
  6. private _items: ExampleItem[]
  7. ) {}
  8. static valueOf(
  9. { count, next, previous, results }:
  10. {
  11. count : number,
  12. next : string | null,
  13. previous: string | null,
  14. results : Array<any>
  15. }
  16. ): ExampleItemList {
  17. const items = results.map(item => ExampleItem.valueOf(item))
  18. return new ExampleItemList(
  19. count,
  20. next,
  21. previous,
  22. items
  23. )
  24. }
  25. get count() {
  26. return this._count
  27. }
  28. get next() {
  29. return this._next
  30. }
  31. get prev() {
  32. return this._prev
  33. }
  34. get items(): ExampleItem[] {
  35. return this._items
  36. }
  37. }
  38. export class ExampleItem {
  39. constructor(
  40. public id: number,
  41. public text: string,
  42. public meta: object,
  43. public annotationApprover: boolean | null,
  44. public commentCount: number,
  45. public fileUrl: string,
  46. public isConfirmed: boolean
  47. ) {}
  48. static valueOf(
  49. { id, text, meta, annotation_approver, comment_count, filename, is_confirmed }:
  50. {
  51. id: number,
  52. text: string,
  53. meta: object,
  54. annotation_approver: boolean | null,
  55. comment_count: number,
  56. filename: string,
  57. is_confirmed: boolean
  58. }
  59. ): ExampleItem {
  60. return new ExampleItem(id, text, meta, annotation_approver, comment_count, filename, is_confirmed)
  61. }
  62. get url() {
  63. const l = this.fileUrl.indexOf('media/')
  64. const r = this.fileUrl.indexOf('media/', l + 1)
  65. return this.fileUrl.slice(0, l) + this.fileUrl.slice(r)
  66. }
  67. get filename() {
  68. const items = this.fileUrl.split('/')
  69. return items[items.length - 1]
  70. }
  71. toObject(): Object {
  72. return {
  73. id: this.id,
  74. text: this.text,
  75. meta: this.meta,
  76. annotation_approver: this.annotationApprover,
  77. comment_count: this.commentCount
  78. }
  79. }
  80. }