Commit bc71e2cf authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '399-can-not-print-the-labels' into 'main'

Can not print the labels.

Closes #399

See merge request grin-global/grin-global-ui!389
parents 89bfd163 2f6ad48d
......@@ -12,7 +12,7 @@ import * as QueryString from "query-string";
const URL_CODE_VALUES_LIST = '/api/v1/app/codes';
// const URL_APP_RESOURCES_LIST = UrlTemplate.parse('/api/v1/app/resources/{appName}/{lang}');
const URL_APP_SETTINGS_MINI = '/api/v1/app/settings';
const URL_APP_SETTINGS_GETSETTING = UrlTemplate.parse('/api/v1/app/setting/{name}');
const URL_APP_SETTINGS_GETSETTING = '/api/v1/app/setting'
const URL_APP_SETTINGS_LIST = `/api/v1/app/settings/list`;
const URL_UPDATE_APP_SETTING = `/api/v1/app/settings/set`;
const URL_APP_LANGUAGES_LIST = '/api/v1/app/languages';
......@@ -135,9 +135,9 @@ class ApplicationService {
* @param categoryTag (Optional) Setting Category tag
* @param xhrConfig additional xhr config
*/
public getSetting = (name: string, categoryTag?: string, xhrConfig?: AxiosRequestConfig): Promise<string> => {
public getSettings = (name: string, categoryTag?: string, xhrConfig?: AxiosRequestConfig): Promise<AppSetting[]> => {
const apiUrl = URL_APP_SETTINGS_GETSETTING.expand({ name });
const apiUrl = URL_APP_SETTINGS_GETSETTING
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
......@@ -147,9 +147,10 @@ class ApplicationService {
method: 'GET',
params: {
categoryTag,
name
},
...content,
}).then(({ data }) => data as string);
}).then(({ data }) => data as AppSetting[]);
}
/**
......
......@@ -9,7 +9,6 @@ import { printLabels } from "@gringlobal-ce/client/utilities";
import { showSnackbar } from "@gringlobal-ce/client/action/snackbar";
import { ApplicationService } from "@gringlobal-ce/client/service";
import { closeDialog } from "@gringlobal-ce/client/action/dialog";
import { loadAllPages } from "@gringlobal-ce/client/utilities";
interface IPrintLabelProps extends React.ClassAttributes<any>, WithTranslation, WithWidth {
labelsGenerator: (...args: any[]) => Generator | { [key: string]: any }[];
......@@ -41,10 +40,9 @@ class PrintLabelDialog extends React.Component<IPrintLabelProps, any> {
private checkMultiple = () => {
const { templateName, showSnackbar, t } = this.props;
loadAllPages(ApplicationService, ApplicationService.appSettingsList).then((settings) => {
const labelTemplates = settings.filter((setting) => setting.categoryTag === 'LABEL' && setting.name.startsWith(templateName))
if (labelTemplates.length > 0) {
this.setState({ templates: labelTemplates })
ApplicationService.getSettings(templateName, 'LABEL').then((settings) => {
if (settings.length > 0) {
this.setState({ templates: settings })
return;
}
showSnackbar(t('public.c.printLabel.noTemplateFound', { templateName }))
......
......@@ -14,7 +14,6 @@ import { bindActionCreators } from "redux";
import { showSnackbar } from "@gringlobal-ce/client/action/snackbar";
import AppSetting from "@gringlobal-ce/client/model/gringlobal/AppSetting";
import { CodeValueDisplay } from './CodeValue';
import { loadAllPages } from "@gringlobal-ce/client/utilities";
const PrintLabelForm = ({ t, onSubmit, initialValues, templateName, templates, showSnackbar, error }:
{ showSnackbar: (msg) => void, onSubmit: (values) => void, templates?: AppSetting[], templateName?: string } & FormProps & WithTranslation) => {
......@@ -24,12 +23,11 @@ const PrintLabelForm = ({ t, onSubmit, initialValues, templateName, templates, s
React.useEffect(() => {
if (!settings && !templates && templateName) {
loadAllPages(ApplicationService, ApplicationService.appSettingsList).then((settings) => {
const labelTemplates = settings.filter((setting) => setting.categoryTag === 'LABEL' && setting.name.startsWith(templateName))
if (labelTemplates.length === 0) {
ApplicationService.getSettings(templateName, 'LABEL').then((settings) => {
if (settings.length === 0) {
setInternalError(t('public.c.printLabel.noTemplateFound', { templateName }))
}
setSettings(labelTemplates)
setSettings(settings)
}).catch((e) => {
console.log('Error getting templates', e)
showSnackbar(t('common:label.errorHappened'));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment