2020-03-05 13:08:19 -05:00
|
|
|
import sidebarDetailsQuery from 'ee_else_ce/sidebar/queries/sidebarDetails.query.graphql';
|
2020-08-17 17:09:56 -04:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import createGqClient, { fetchPolicies } from '~/lib/graphql';
|
2020-03-05 13:08:19 -05:00
|
|
|
|
|
|
|
export const gqClient = createGqClient(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
fetchPolicy: fetchPolicies.NO_CACHE,
|
|
|
|
},
|
|
|
|
);
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
export default class SidebarService {
|
2017-08-14 03:26:19 -04:00
|
|
|
constructor(endpointMap) {
|
2017-05-04 08:11:15 -04:00
|
|
|
if (!SidebarService.singleton) {
|
2017-08-14 03:26:19 -04:00
|
|
|
this.endpoint = endpointMap.endpoint;
|
2017-10-31 12:15:03 -04:00
|
|
|
this.toggleSubscriptionEndpoint = endpointMap.toggleSubscriptionEndpoint;
|
2017-08-14 03:26:19 -04:00
|
|
|
this.moveIssueEndpoint = endpointMap.moveIssueEndpoint;
|
|
|
|
this.projectsAutocompleteEndpoint = endpointMap.projectsAutocompleteEndpoint;
|
2020-03-05 13:08:19 -05:00
|
|
|
this.fullPath = endpointMap.fullPath;
|
2020-03-13 11:09:21 -04:00
|
|
|
this.iid = endpointMap.iid;
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
SidebarService.singleton = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SidebarService.singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
get() {
|
2020-03-05 13:08:19 -05:00
|
|
|
return Promise.all([
|
|
|
|
axios.get(this.endpoint),
|
|
|
|
gqClient.query({
|
2020-09-01 02:10:44 -04:00
|
|
|
query: sidebarDetailsQuery,
|
2020-03-05 13:08:19 -05:00
|
|
|
variables: {
|
|
|
|
fullPath: this.fullPath,
|
2020-03-13 11:09:21 -04:00
|
|
|
iid: this.iid.toString(),
|
2020-03-05 13:08:19 -05:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
]);
|
2017-05-04 08:11:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
update(key, data) {
|
2019-09-10 15:07:06 -04:00
|
|
|
return axios.put(this.endpoint, { [key]: data });
|
2017-05-04 08:11:15 -04:00
|
|
|
}
|
2017-08-14 03:26:19 -04:00
|
|
|
|
2020-03-13 11:09:21 -04:00
|
|
|
updateWithGraphQl(mutation, variables) {
|
|
|
|
return gqClient.mutate({
|
|
|
|
mutation,
|
|
|
|
variables: {
|
|
|
|
...variables,
|
|
|
|
projectPath: this.fullPath,
|
|
|
|
iid: this.iid.toString(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-14 03:26:19 -04:00
|
|
|
getProjectsAutocomplete(searchTerm) {
|
2019-09-10 15:07:06 -04:00
|
|
|
return axios.get(this.projectsAutocompleteEndpoint, {
|
2017-08-14 03:26:19 -04:00
|
|
|
params: {
|
|
|
|
search: searchTerm,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-31 12:15:03 -04:00
|
|
|
toggleSubscription() {
|
2019-09-10 15:07:06 -04:00
|
|
|
return axios.post(this.toggleSubscriptionEndpoint);
|
2017-10-31 12:15:03 -04:00
|
|
|
}
|
|
|
|
|
2017-08-14 03:26:19 -04:00
|
|
|
moveIssue(moveToProjectId) {
|
2019-09-10 15:07:06 -04:00
|
|
|
return axios.post(this.moveIssueEndpoint, {
|
2017-08-14 03:26:19 -04:00
|
|
|
move_to_project_id: moveToProjectId,
|
|
|
|
});
|
|
|
|
}
|
2017-05-04 08:11:15 -04:00
|
|
|
}
|