Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to print qr code labels using datalab gateway #887

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions webapp/src/gateway_fetch_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// utility functions to deal with fetch calls to datalab gateway servers
// all code using fetch should be collected into this file

// import store from "@/store/index.js";
import { GATEWAY_URL } from "@/resources.js";

import { fetch_post } from "@/server_fetch_utils.js";

export function printQRCode(item_id, name, url, hcodes, isDryrun) {
return fetch_post(`${GATEWAY_URL}/print-label`, {
item_id: item_id,
name: name,
url: url,
hcodes: hcodes,
dryrun: isDryrun,
});
}
2 changes: 2 additions & 0 deletions webapp/src/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const API_TOKEN = process.env.VUE_APP_API_TOKEN;

export const QR_CODE_RESOLVER_URL = process.env.VUE_APP_QR_CODE_RESOLVER_URL;

export const GATEWAY_URL = process.env.VUE_APP_GATEWAY_URL;

export const FEDERATION_QR_CODE_RESOLVER_URL = "https://purl.datalab-org.io";

export const LOGO_URL = process.env.VUE_APP_LOGO_URL;
Expand Down
10 changes: 5 additions & 5 deletions webapp/src/server_fetch_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function construct_headers(additional_headers = null) {
}

// eslint-disable-next-line no-unused-vars
function fetch_get(url) {
export function fetch_get(url) {
const requestOptions = {
method: "GET",
headers: construct_headers(),
Expand All @@ -34,7 +34,7 @@ function fetch_get(url) {
return fetch(url, requestOptions).then(handleResponse);
}

function fetch_post(url, body) {
export function fetch_post(url, body) {
let headers = construct_headers({ "Content-Type": "application/json" });
const requestOptions = {
method: "POST",
Expand All @@ -45,7 +45,7 @@ function fetch_post(url, body) {
return fetch(url, requestOptions).then(handleResponse);
}

function fetch_patch(url, body) {
export function fetch_patch(url, body) {
let headers = construct_headers({ "Content-Type": "application/json" });
const requestOptions = {
method: "PATCH",
Expand All @@ -57,7 +57,7 @@ function fetch_patch(url, body) {
}

// eslint-disable-next-line no-unused-vars
function fetch_put(url, body) {
export function fetch_put(url, body) {
let headers = construct_headers({ "Content-Type": "application/json" });
const requestOptions = {
method: "PUT",
Expand All @@ -69,7 +69,7 @@ function fetch_put(url, body) {
}

// eslint-disable-next-line no-unused-vars
function fetch_delete(url) {
export function fetch_delete(url) {
let headers = construct_headers({ "Content-Type": "application/json" });
const requestOptions = {
method: "DELETE",
Expand Down
11 changes: 11 additions & 0 deletions webapp/src/views/EditPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<a class="nav-item nav-link" :href="itemApiUrl" target="_blank">
<font-awesome-icon icon="code" fixed-width /> View JSON
</a>
<a class="nav-item nav-link" @click="printLabel">Print label</a>
</div>
<div class="navbar-nav ml-auto">
<span v-if="itemDataLoaded && !savedStatus" class="navbar-text unsaved-warning">
Expand Down Expand Up @@ -102,6 +103,7 @@ import {
updateBlockFromServer,
getBlocksInfos,
} from "@/server_fetch_utils";
import { printQRCode } from "@/gateway_fetch_utils.js";
import FormattedItemName from "@/components/FormattedItemName";

import setupUppy from "@/file_upload.js";
Expand Down Expand Up @@ -299,6 +301,15 @@ export default {
});
this.setLastModified();
},
printLabel() {
printQRCode(
this.item_data.item_id,
this.item_data.name,
"https://demo.datalab-io.org",
this.item_data.GHS_codes,
false,
);
},
leavePageWarningListener(event) {
event.preventDefault;
return (event.returnValue =
Expand Down