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.

81 lines
1.7 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. ) {}
  47. static valueOf(
  48. { id, text, meta, annotation_approver, comment_count, filename }:
  49. { id: number, text: string, meta: object, annotation_approver: boolean | null, comment_count: number, filename: string }
  50. ): ExampleItem {
  51. return new ExampleItem(id, text, meta, annotation_approver, comment_count, filename)
  52. }
  53. get url() {
  54. const l = this.fileUrl.indexOf('media/')
  55. const r = this.fileUrl.indexOf('media/', l + 1)
  56. return this.fileUrl.slice(0, l) + this.fileUrl.slice(r)
  57. }
  58. get filename() {
  59. const items = this.fileUrl.split('/')
  60. return items[items.length - 1]
  61. }
  62. toObject(): Object {
  63. return {
  64. id: this.id,
  65. text: this.text,
  66. meta: this.meta,
  67. annotation_approver: this.annotationApprover,
  68. comment_count: this.commentCount
  69. }
  70. }
  71. }