Skip to content

Commit

Permalink
Merge pull request #1582 from terrestris/print-templates
Browse files Browse the repository at this point in the history
feat: creates ability to select app specific print templates
  • Loading branch information
dnlkoch committed Jun 24, 2024
2 parents b7d698a + 087fb07 commit ac5b043
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import {
import {
setLogoPath
} from './store/logoPath';
import { setPrintApp } from './store/print';
import {
setSearchEngines
} from './store/searchEngines';
Expand Down Expand Up @@ -687,6 +688,11 @@ const renderApp = async () => {
i18n.changeLanguage(defaultLanguage);
}

const printApp = appConfig?.clientConfig?.printApp;
if (printApp) {
store.dispatch(setPrintApp(printApp));
}

const style = parseTheme(appConfig?.clientConfig?.theme);

ConfigProvider.config({
Expand Down
14 changes: 9 additions & 5 deletions src/components/PrintForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const PrintForm: React.FC<PrintFormProps> = ({
customPrintScales = [],

layerBlackList = [],
outputFormats= ['pdf', 'png'],
outputFormats = ['pdf', 'png'],
...restProps
}): JSX.Element => {

Expand All @@ -93,6 +93,7 @@ export const PrintForm: React.FC<PrintFormProps> = ({

const customMapParams = useAppSelector(state => state.print.customMapParams);
const customParams = useAppSelector(state => state.print.customParams);
const printApp = useAppSelector(state => state.print.printApp);

const [printManager, setPrintManager] = useState<MapFishPrintV3Manager | null>(null);
const [loading, setLoading] = useState<boolean>(false);
Expand Down Expand Up @@ -225,9 +226,12 @@ export const PrintForm: React.FC<PrintFormProps> = ({
// Use locale print app if available.
// Implies that a print app with the language code exists.
const apps = pManager.getPrintApps();

if (apps && currentLanguageCode && apps.includes(currentLanguageCode)) {
await pManager.setPrintApp(currentLanguageCode);
if (!printApp) {
if (apps && currentLanguageCode && apps.includes(currentLanguageCode)) {
await pManager.setPrintApp(currentLanguageCode);
}
} else {
await pManager.setPrintApp(printApp);
}

pManager.setOutputFormat(pManager.getOutputFormats()[0]);
Expand All @@ -238,7 +242,7 @@ export const PrintForm: React.FC<PrintFormProps> = ({
setErrorMsg(() => t('PrintForm.managerErrorMessage'));
Logger.error('Could not initialize print manager: ', error);
}
}, [map, layerFilter, client, legendFilter, customPrintScales, currentLanguageCode, t]);
}, [map, layerFilter, client, legendFilter, customPrintScales, printApp, currentLanguageCode, t]);

useEffect(() => {
if (printManager) {
Expand Down
8 changes: 7 additions & 1 deletion src/store/print/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { V3CustomMapParams } from '@terrestris/mapfish-print-manager/dist/manage
export type PrintState = {
customMapParams?: V3CustomMapParams;
customParams?: any;
printApp?: string;
};

const initialState: PrintState = {
printApp: 'default',
customMapParams: {},
customParams: {
printLegend: false
Expand All @@ -27,6 +29,9 @@ export const printSlice = createSlice({
setCustomParams: (state, action: PayloadAction<any>) => {
state.customParams = action.payload;
},
setPrintApp: (state, action: PayloadAction<string>) => {
state.printApp = action.payload;
},
addCustomMapParam: (state, action: PayloadAction<Partial<V3CustomMapParams>>) => {
state.customMapParams = {
...state.customMapParams,
Expand All @@ -46,7 +51,8 @@ export const {
setCustomMapParams,
setCustomParams,
addCustomMapParam,
addCustomParam
addCustomParam,
setPrintApp
} = printSlice.actions;

export default printSlice.reducer;

0 comments on commit ac5b043

Please sign in to comment.