Skip to content

Commit

Permalink
Fix edit button (#228)
Browse files Browse the repository at this point in the history
* Fix edit button

* Fix source
  • Loading branch information
oeway authored Jan 18, 2022
1 parent 83129ed commit 495ac10
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bioimage",
"version": "0.4.2",
"version": "0.4.3",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand All @@ -23,7 +23,7 @@
"js-yaml": "^4.1.0",
"json-stringify-safe": "^5.0.1",
"jszip": "^3.7.0",
"marked": "^2.0.0",
"marked": "^2.1.3",
"mathjs": "^7.5.1",
"ol": "^6.3.1",
"register-service-worker": "^1.7.1",
Expand Down
5 changes: 4 additions & 1 deletion src/components/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,10 @@ export default {
});
try {
if (!this.client.credential) await this.login();
this.URI4Load = `${this.zenodoBaseURL}/record/${this.updateDepositId}`;
// example: updateDepositId=10.5281/zenodo.5850574
this.URI4Load = `${this.zenodoBaseURL}/record/${
this.updateDepositId.split("zenodo.")[1]
}`;
await this.loadRdfFromURL(this.URI4Load);
} catch (e) {
alert("Failed to load resource: " + this.updateDepositId);
Expand Down
10 changes: 7 additions & 3 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,20 @@ export const store = new Vuex.Store({
typeof author === "string" ? { name: author } : author
);
item.config = item.config || {};
if (item.config._deposit) {
if (item.owners) {
const userId = state.zenodoClient && state.zenodoClient.getUserId();

if (userId && item.config._deposit.owners.includes(userId)) {
if (userId && item.owners.includes(userId)) {
if (!item.tags.includes("editable")) item.tags.push("editable");
}
}
item.config._rdf_file =
item.config._rdf_file || item.rdf_source || item.source; // TODO: some resources current doesn't have a dedicated rdf_file
if (item.type === "application" && item?.source?.endsWith(".imjoy.html"))
if (
item.type === "application" &&
typeof item.source === "string" &&
item.source.endsWith(".imjoy.html")
)
state.allApps[item.id] = item;
item.tags = item.tags.map(tag => tag.toLowerCase());
item.tags.map(tag => {
Expand Down
36 changes: 25 additions & 11 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@
</template>

<script>
import yaml from "js-yaml";
import { mapState } from "vuex";
import spdxLicenseList from "spdx-license-list/full";
import ResourceItemSelector from "@/components/ResourceItemSelector.vue";
Expand All @@ -346,7 +347,7 @@ const DEFAULT_ICONS = {
model: "hubspot"
};
import { setupDevMenu, runAppForItem, runAppForAllItems } from "../bioEngine";
import { concatAndResolveUrl, debounce, getFullRdfFromDeposit } from "../utils";
import { concatAndResolveUrl, debounce } from "../utils";
function titleCase(str) {
return str.replace(/_/g, " ").replace(/(^|\s)\S/g, function(t) {
Expand All @@ -363,12 +364,18 @@ const isTouchDevice = (function() {
})();
async function updateFullRDF(item) {
if (item.config._deposit) {
const newRDF = await getFullRdfFromDeposit(item.config._deposit, true);
for (let k of Object.keys(newRDF)) {
if (k !== "config") {
item[k] = newRDF[k];
if (item.rdf_source) {
const response = await fetch(item.rdf_source);
if (response.ok) {
const yamlStr = await response.text();
const newRDF = yaml.load(yamlStr);
for (let k of Object.keys(newRDF)) {
if (k !== "config") {
item[k] = newRDF[k];
}
}
} else {
throw new Error(`Oops, failed to fetch RDF file.`);
}
}
}
Expand Down Expand Up @@ -424,16 +431,16 @@ function normalizeItem(self, item) {
);
item.apps = [];
if (item.config._deposit) {
if (item.config._deposit.owners.includes(self.userId)) {
if (item.owners) {
if (item.owners.includes(self.userId)) {
item.apps.unshift({
name: "Edit",
icon: "pencil",
show_on_hover: true,
run() {
self.$router.push({
name: "Update",
params: { updateDepositId: item.config._deposit.id }
params: { updateDepositId: item.id }
});
}
});
Expand Down Expand Up @@ -490,11 +497,18 @@ function normalizeItem(self, item) {
runAppForAllItems(self, self.allApps[item.id], self.resourceItems);
}
});
} else if (item.tags.includes("colab") && item.source.endsWith(".ipynb")) {
} else if (
item.tags.includes("colab") &&
item.source &&
item.source.endsWith(".ipynb")
) {
// convert github raw url to colab url
item.config = item.config || {};
if (item.source.startsWith("https://raw.githubusercontent.com/")) {
if (
item.source &&
item.source.startsWith("https://raw.githubusercontent.com/")
) {
const b = item.source.split("/");
item.config._colab_url = `https://colab.research.google.com/github/${
b[3]
Expand Down

0 comments on commit 495ac10

Please sign in to comment.