summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/models/image-spec.ts
blob: 8b56b291c73f042a599e5f9ca5da71057ee3b8b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
export class ImageSpec {
  static fromString(imageSpec: string) {
    const imageSpecSplited = imageSpec.split('/');

    const poolName = imageSpecSplited[0];
    const namespace = imageSpecSplited.length >= 3 ? imageSpecSplited[1] : null;
    const imageName = imageSpecSplited.length >= 3 ? imageSpecSplited[2] : imageSpecSplited[1];

    return new this(poolName, namespace, imageName);
  }

  constructor(public poolName: string, public namespace: string, public imageName: string) {}

  private getNameSpace() {
    return this.namespace ? `${this.namespace}/` : '';
  }

  toString() {
    return `${this.poolName}/${this.getNameSpace()}${this.imageName}`;
  }

  toStringEncoded() {
    return encodeURIComponent(`${this.poolName}/${this.getNameSpace()}${this.imageName}`);
  }
}