github.com/hernad/nomad@v1.6.112/ui/app/adapters/recommendation-summary.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import ApplicationAdapter from './application'; 7 import classic from 'ember-classic-decorator'; 8 9 @classic 10 export default class RecommendationSummaryAdapter extends ApplicationAdapter { 11 pathForType = () => 'recommendations'; 12 13 urlForFindAll() { 14 const url = super.urlForFindAll(...arguments); 15 return `${url}?namespace=*`; 16 } 17 18 updateRecord(store, type, snapshot) { 19 const url = `${super.urlForCreateRecord( 20 'recommendations', 21 snapshot 22 )}/apply`; 23 24 const allRecommendationIds = snapshot 25 .hasMany('recommendations') 26 .mapBy('id'); 27 const excludedRecommendationIds = ( 28 snapshot.hasMany('excludedRecommendations') || [] 29 ).mapBy('id'); 30 const includedRecommendationIds = allRecommendationIds.removeObjects( 31 excludedRecommendationIds 32 ); 33 34 const data = { 35 Apply: includedRecommendationIds, 36 Dismiss: excludedRecommendationIds, 37 }; 38 39 return this.ajax(url, 'POST', { data }); 40 } 41 }