github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/adapters/deployment.js (about)

     1  import Watchable from './watchable';
     2  import classic from 'ember-classic-decorator';
     3  
     4  @classic
     5  export default class DeploymentAdapter extends Watchable {
     6    fail(deployment) {
     7      const id = deployment.get('id');
     8      const url = urlForAction(this.urlForFindRecord(id, 'deployment'), '/fail');
     9      return this.ajax(url, 'POST', {
    10        data: {
    11          DeploymentId: id,
    12        },
    13      });
    14    }
    15  
    16    promote(deployment) {
    17      const id = deployment.get('id');
    18      const url = urlForAction(
    19        this.urlForFindRecord(id, 'deployment'),
    20        '/promote'
    21      );
    22      return this.ajax(url, 'POST', {
    23        data: {
    24          DeploymentId: id,
    25          All: true,
    26        },
    27      });
    28    }
    29  }
    30  
    31  // The deployment action API endpoints all end with the ID
    32  // /deployment/:action/:deployment_id instead of /deployment/:deployment_id/:action
    33  function urlForAction(url, extension = '') {
    34    const [path, params] = url.split('?');
    35    const pathParts = path.split('/');
    36    const idPart = pathParts.pop();
    37    let newUrl = `${pathParts.join('/')}${extension}/${idPart}`;
    38  
    39    if (params) {
    40      newUrl += `?${params}`;
    41    }
    42  
    43    return newUrl;
    44  }