Collection.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { ChildrenStatusType, StatusEnum } from '../components/status/Types';
  2. import { CollectionView } from '../pages/collections/Types';
  3. import { IndexState } from '../types/Milvus';
  4. import BaseModel from './BaseModel';
  5. export class CollectionHttp extends BaseModel implements CollectionView {
  6. private autoID!: string;
  7. private collection_name!: string;
  8. private description!: string;
  9. private rowCount!: string;
  10. private index_status!: string;
  11. static COLLECTIONS_URL = '/collections';
  12. static COLLECTIONS_INDEX_STATUS_URL = '/collections/indexes/status';
  13. static CHECK_URL = '/milvus/check';
  14. constructor(props: CollectionView) {
  15. super(props);
  16. Object.assign(this, props);
  17. }
  18. static getCollections(): Promise<CollectionHttp[]> {
  19. return super.findAll({ path: this.COLLECTIONS_URL, params: {} });
  20. }
  21. static getCollectionsIndexState(): Promise<CollectionHttp[]> {
  22. return super.findAll({
  23. path: this.COLLECTIONS_INDEX_STATUS_URL,
  24. params: {},
  25. });
  26. }
  27. get _autoId() {
  28. return this.autoID;
  29. }
  30. get _desc() {
  31. return this.description;
  32. }
  33. get _id() {
  34. return '12';
  35. }
  36. get _name() {
  37. return this.collection_name;
  38. }
  39. get _rowCount() {
  40. return this.rowCount;
  41. }
  42. get _status() {
  43. return StatusEnum.loaded;
  44. }
  45. get _indexState() {
  46. switch (this.index_status) {
  47. case IndexState.InProgress:
  48. return ChildrenStatusType.CREATING;
  49. case IndexState.Failed:
  50. return ChildrenStatusType.ERROR;
  51. default:
  52. return ChildrenStatusType.FINISH;
  53. }
  54. }
  55. }