github.com/hernad/nomad@v1.6.112/ui/app/adapters/deployment.js (about)

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