Skip to content

Commit 495ac10

Browse files
authored
Fix edit button (#228)
* Fix edit button * Fix source
1 parent 83129ed commit 495ac10

File tree

5 files changed

+39
-18
lines changed

5 files changed

+39
-18
lines changed

Diff for: package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bioimage",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",
@@ -23,7 +23,7 @@
2323
"js-yaml": "^4.1.0",
2424
"json-stringify-safe": "^5.0.1",
2525
"jszip": "^3.7.0",
26-
"marked": "^2.0.0",
26+
"marked": "^2.1.3",
2727
"mathjs": "^7.5.1",
2828
"ol": "^6.3.1",
2929
"register-service-worker": "^1.7.1",

Diff for: src/components/Upload.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,10 @@ export default {
527527
});
528528
try {
529529
if (!this.client.credential) await this.login();
530-
this.URI4Load = `${this.zenodoBaseURL}/record/${this.updateDepositId}`;
530+
// example: updateDepositId=10.5281/zenodo.5850574
531+
this.URI4Load = `${this.zenodoBaseURL}/record/${
532+
this.updateDepositId.split("zenodo.")[1]
533+
}`;
531534
await this.loadRdfFromURL(this.URI4Load);
532535
} catch (e) {
533536
alert("Failed to load resource: " + this.updateDepositId);

Diff for: src/store.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,20 @@ export const store = new Vuex.Store({
122122
typeof author === "string" ? { name: author } : author
123123
);
124124
item.config = item.config || {};
125-
if (item.config._deposit) {
125+
if (item.owners) {
126126
const userId = state.zenodoClient && state.zenodoClient.getUserId();
127127

128-
if (userId && item.config._deposit.owners.includes(userId)) {
128+
if (userId && item.owners.includes(userId)) {
129129
if (!item.tags.includes("editable")) item.tags.push("editable");
130130
}
131131
}
132132
item.config._rdf_file =
133133
item.config._rdf_file || item.rdf_source || item.source; // TODO: some resources current doesn't have a dedicated rdf_file
134-
if (item.type === "application" && item?.source?.endsWith(".imjoy.html"))
134+
if (
135+
item.type === "application" &&
136+
typeof item.source === "string" &&
137+
item.source.endsWith(".imjoy.html")
138+
)
135139
state.allApps[item.id] = item;
136140
item.tags = item.tags.map(tag => tag.toLowerCase());
137141
item.tags.map(tag => {

Diff for: src/views/Home.vue

+25-11
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@
329329
</template>
330330

331331
<script>
332+
import yaml from "js-yaml";
332333
import { mapState } from "vuex";
333334
import spdxLicenseList from "spdx-license-list/full";
334335
import ResourceItemSelector from "@/components/ResourceItemSelector.vue";
@@ -346,7 +347,7 @@ const DEFAULT_ICONS = {
346347
model: "hubspot"
347348
};
348349
import { setupDevMenu, runAppForItem, runAppForAllItems } from "../bioEngine";
349-
import { concatAndResolveUrl, debounce, getFullRdfFromDeposit } from "../utils";
350+
import { concatAndResolveUrl, debounce } from "../utils";
350351
351352
function titleCase(str) {
352353
return str.replace(/_/g, " ").replace(/(^|\s)\S/g, function(t) {
@@ -363,12 +364,18 @@ const isTouchDevice = (function() {
363364
})();
364365
365366
async function updateFullRDF(item) {
366-
if (item.config._deposit) {
367-
const newRDF = await getFullRdfFromDeposit(item.config._deposit, true);
368-
for (let k of Object.keys(newRDF)) {
369-
if (k !== "config") {
370-
item[k] = newRDF[k];
367+
if (item.rdf_source) {
368+
const response = await fetch(item.rdf_source);
369+
if (response.ok) {
370+
const yamlStr = await response.text();
371+
const newRDF = yaml.load(yamlStr);
372+
for (let k of Object.keys(newRDF)) {
373+
if (k !== "config") {
374+
item[k] = newRDF[k];
375+
}
371376
}
377+
} else {
378+
throw new Error(`Oops, failed to fetch RDF file.`);
372379
}
373380
}
374381
}
@@ -424,16 +431,16 @@ function normalizeItem(self, item) {
424431
);
425432
item.apps = [];
426433
427-
if (item.config._deposit) {
428-
if (item.config._deposit.owners.includes(self.userId)) {
434+
if (item.owners) {
435+
if (item.owners.includes(self.userId)) {
429436
item.apps.unshift({
430437
name: "Edit",
431438
icon: "pencil",
432439
show_on_hover: true,
433440
run() {
434441
self.$router.push({
435442
name: "Update",
436-
params: { updateDepositId: item.config._deposit.id }
443+
params: { updateDepositId: item.id }
437444
});
438445
}
439446
});
@@ -490,11 +497,18 @@ function normalizeItem(self, item) {
490497
runAppForAllItems(self, self.allApps[item.id], self.resourceItems);
491498
}
492499
});
493-
} else if (item.tags.includes("colab") && item.source.endsWith(".ipynb")) {
500+
} else if (
501+
item.tags.includes("colab") &&
502+
item.source &&
503+
item.source.endsWith(".ipynb")
504+
) {
494505
// convert github raw url to colab url
495506
item.config = item.config || {};
496507
497-
if (item.source.startsWith("https://raw.githubusercontent.com/")) {
508+
if (
509+
item.source &&
510+
item.source.startsWith("https://raw.githubusercontent.com/")
511+
) {
498512
const b = item.source.split("/");
499513
item.config._colab_url = `https://colab.research.google.com/github/${
500514
b[3]

0 commit comments

Comments
 (0)