mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
refactor dataset services
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getAppRoot } from "onload/loadConfig";
|
||||
import { Services } from "components/Dataset/services";
|
||||
import { mapCacheActions } from "vuex-cache";
|
||||
|
||||
@@ -50,7 +49,7 @@ export default {
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.services = new Services({ root: getAppRoot() });
|
||||
this.services = new Services();
|
||||
this.pathDestination = {};
|
||||
if (this.path && this.path !== "undefined") {
|
||||
// download individual file from composite dataset
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
</template>
|
||||
<script>
|
||||
import store from "store";
|
||||
import { getAppRoot } from "onload/loadConfig";
|
||||
import { getGalaxyInstance } from "app";
|
||||
import { Services } from "./services";
|
||||
import DatasetName from "./DatasetName";
|
||||
@@ -106,8 +105,7 @@ export default {
|
||||
},
|
||||
created() {
|
||||
this.loadHistories();
|
||||
this.root = getAppRoot();
|
||||
this.services = new Services({ root: this.root });
|
||||
this.services = new Services();
|
||||
this.load();
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { getAppRoot } from "onload/loadConfig";
|
||||
import { Services } from "components/Dataset/services";
|
||||
import store from "../../store/index";
|
||||
|
||||
export const getPathDestination = async (history_dataset_id, path) => {
|
||||
const services = new Services({ root: getAppRoot() });
|
||||
const services = new Services();
|
||||
|
||||
const computePathDestination = (pathDestination) => {
|
||||
if (path === undefined || path === "undefined") {
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import axios from "axios";
|
||||
import { safePath } from "utils/redirect";
|
||||
import { rethrowSimple } from "utils/simple-error";
|
||||
|
||||
/** Datasets request helper **/
|
||||
export class Services {
|
||||
constructor(options = {}) {
|
||||
this.root = options.root;
|
||||
}
|
||||
|
||||
async getDatasets(options = {}) {
|
||||
let params = "";
|
||||
if (options.sortBy) {
|
||||
@@ -22,72 +19,54 @@ export class Services {
|
||||
if (options.query) {
|
||||
params += `q=name-contains&qv=${options.query}&`;
|
||||
}
|
||||
const url = `${this.root}api/datasets?${params}`;
|
||||
const url = `/api/datasets?${params}`;
|
||||
try {
|
||||
const { data } = await axios.get(url);
|
||||
const { data } = await axios.get(safePath(url));
|
||||
return data;
|
||||
} catch (e) {
|
||||
this._errorMessage(e);
|
||||
rethrowSimple(e);
|
||||
}
|
||||
}
|
||||
|
||||
async copyDataset(dataset_id, history_id, type = "dataset", source = "hda") {
|
||||
const url = `${this.root}api/histories/${history_id}/contents`;
|
||||
async copyDataset(datasetId, historyId, type = "dataset", source = "hda") {
|
||||
const url = `/api/histories/${historyId}/contents`;
|
||||
try {
|
||||
const response = await axios.post(url, {
|
||||
const response = await axios.post(safePath(url), {
|
||||
type: type,
|
||||
source: source,
|
||||
content: dataset_id,
|
||||
content: datasetId,
|
||||
});
|
||||
return response.data;
|
||||
} catch (e) {
|
||||
this._errorMessage(e);
|
||||
}
|
||||
}
|
||||
|
||||
async updateTags(item_id, item_class, item_tags) {
|
||||
const url = `${this.root}api/tags`;
|
||||
try {
|
||||
const response = await axios.put(url, {
|
||||
item_id: item_id,
|
||||
item_class: item_class,
|
||||
item_tags: item_tags,
|
||||
});
|
||||
return response.data;
|
||||
} catch (e) {
|
||||
this._errorMessage(e);
|
||||
}
|
||||
}
|
||||
|
||||
async getCompositeDatasetContentFiles(id) {
|
||||
const url = `${this.root}api/histories/${id}/contents/${id}/extra_files`;
|
||||
try {
|
||||
const response = await axios.get(url);
|
||||
return response.data;
|
||||
} catch (e) {
|
||||
rethrowSimple(e);
|
||||
}
|
||||
}
|
||||
|
||||
getCompositeDatasetLink(history_dataset_id, path) {
|
||||
return `${this.root}api/histories/${history_dataset_id}/contents/${history_dataset_id}/display?filename=${path}`;
|
||||
async updateTags(itemId, itemClass, itemTags) {
|
||||
const url = `/api/tags`;
|
||||
try {
|
||||
const response = await axios.put(safePath(url), {
|
||||
item_id: itemId,
|
||||
item_class: itemClass,
|
||||
item_tags: itemTags,
|
||||
});
|
||||
return response.data;
|
||||
} catch (e) {
|
||||
rethrowSimple(e);
|
||||
}
|
||||
}
|
||||
|
||||
getCompositeDatasetLink(historyDatasetId, path) {
|
||||
return safePath(`/api/histories/${historyDatasetId}/contents/${historyDatasetId}/display?filename=${path}`);
|
||||
}
|
||||
|
||||
async getCompositeDatasetInfo(id) {
|
||||
const url = `${this.root}api/histories/${id}/contents/${id}`;
|
||||
const url = `/api/histories/${id}/contents/${id}`;
|
||||
try {
|
||||
const response = await axios.get(url);
|
||||
const response = await axios.get(safePath(url));
|
||||
return response.data;
|
||||
} catch (e) {
|
||||
rethrowSimple(e);
|
||||
}
|
||||
}
|
||||
|
||||
_errorMessage(e) {
|
||||
let message = "Request failed.";
|
||||
if (e.response) {
|
||||
message = e.response.data.err_msg || `${e.response.statusText} (${e.response.status})`;
|
||||
}
|
||||
throw message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,6 @@
|
||||
import Vue from "vue";
|
||||
import { Toast } from "ui/toast";
|
||||
import { mapActions } from "vuex";
|
||||
import { getAppRoot } from "onload/loadConfig";
|
||||
import { HistoryItemsProvider } from "components/providers/storeProviders";
|
||||
import LoadingSpan from "components/LoadingSpan";
|
||||
import ContentItem from "components/History/Content/ContentItem";
|
||||
@@ -247,8 +246,7 @@ export default {
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.root = getAppRoot();
|
||||
this.datasetServices = new DatasetServices({ root: this.root });
|
||||
this.datasetServices = new DatasetServices();
|
||||
},
|
||||
methods: {
|
||||
...mapActions("history", ["loadHistoryById"]),
|
||||
@@ -319,23 +317,22 @@ export default {
|
||||
},
|
||||
onDrop(evt) {
|
||||
const data = JSON.parse(evt.dataTransfer.getData("text"))[0];
|
||||
const dataSources = data.history_content_type === "dataset" ? "hda" : "hdca";
|
||||
if (data.history_id === this.historyId) {
|
||||
return;
|
||||
const dataSource = data.history_content_type === "dataset" ? "hda" : "hdca";
|
||||
if (data.history_id != this.historyId) {
|
||||
this.datasetServices
|
||||
.copyDataset(data.id, this.historyId, data.history_content_type, dataSource)
|
||||
.then(() => {
|
||||
if (data.history_content_type === "dataset") {
|
||||
Toast.info("Dataset copied to history");
|
||||
} else {
|
||||
Toast.info("Collection copied to history");
|
||||
}
|
||||
this.loadHistoryById(this.historyId);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.onError(error);
|
||||
});
|
||||
}
|
||||
this.datasetServices
|
||||
.copyDataset(data.id, this.historyId, data.history_content_type, dataSources)
|
||||
.then(() => {
|
||||
if (data.history_content_type === "dataset") {
|
||||
Toast.info("Dataset copied to history");
|
||||
} else {
|
||||
Toast.info("Collection copied to history");
|
||||
}
|
||||
this.loadHistoryById(this.historyId);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.onError(error);
|
||||
});
|
||||
},
|
||||
onError(error) {
|
||||
Toast.error(error);
|
||||
|
||||
Reference in New Issue
Block a user