Skip to content

Commit

Permalink
Merge pull request #64 from ezeep/feature/profile-defaults
Browse files Browse the repository at this point in the history
Display printer preset values by default for color, duplex, paper format, resolution, tray fields
  • Loading branch information
tp-shery authored Mar 7, 2024
2 parents 6b287ed + 5f7e5e2 commit 433d243
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 35 deletions.
77 changes: 49 additions & 28 deletions src/components/ezp-printer-selection/ezp-printer-selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class EzpPrinterSelection {
private sasUri = ''
private fileExtension = ''
private printService: EzpPrintService
private duplexOptions = [
public duplexOptions = [
{
id: 1,
title: i18next.t('printer_selection.duplex_none'),
Expand Down Expand Up @@ -80,6 +80,14 @@ export class EzpPrinterSelection {
@State() selectedPrinter: Printer
@State() printerConfig: PrinterConfig[]
@State() selectedPrinterConfig: PrinterConfig = {
Profile: {
Color: '',
Duplex: '',
Paper: '',
Orientation: '',
Resolution: '',
Tray: ''
},
OrientationsSupported: [],
PaperFormats: [],
Resolutions: [],
Expand Down Expand Up @@ -357,8 +365,10 @@ export class EzpPrinterSelection {
this.selectedPrinter.is_queue = eventDetails.is_queue
await this.printService
.getPrinterProperties(authStore.state.accessToken, this.selectedPrinter.id)
.then((data) => (this.selectedPrinterConfig = data[0]))
this.setDefaultPaperFormat()
.then((data) => {
this.selectedPrinterConfig = {...this.selectedPrinterConfig, ...data[0]}
})
// this.setDefaultPaperFormat()
break
case 'color':
this.selectedProperties.color = !!eventDetails.id
Expand Down Expand Up @@ -401,7 +411,7 @@ export class EzpPrinterSelection {
case 'paper_ranges':
this.selectedProperties.PageRanges = eventDetails.value;
this.pageRangeInvalid = !validatePageRange(this.selectedProperties.PageRanges);

localStorage.setItem('pageRanges', JSON.stringify(this.selectedProperties.PageRanges));
// console.log(this.selectedProperties.PageRanges)
break
case 'duplex':
Expand Down Expand Up @@ -503,17 +513,17 @@ export class EzpPrinterSelection {
format = 'A4'
}

if (this.selectedPrinterConfig.PaperFormats.find((el) => el.Name.includes(format))) {
this.selectedProperties.paper = this.selectedPrinterConfig.PaperFormats.find((el) =>
if (this.selectedPrinterConfig.PaperFormats?.find((el) => el.Name.includes(format))) {
this.selectedProperties.paper = this.selectedPrinterConfig.PaperFormats?.find((el) =>
el.Name.includes(format)
).Name
this.selectedProperties.paperid = this.selectedPrinterConfig.PaperFormats.find((el) =>
this.selectedProperties.paperid = this.selectedPrinterConfig.PaperFormats?.find((el) =>
el.Name.includes(format)
).Id

} else {
this.selectedProperties.paper = this.selectedPrinterConfig.PaperFormats[0].Name
this.selectedProperties.paperid = this.selectedPrinterConfig.PaperFormats[0].Id
this.selectedProperties.paper = this.selectedPrinterConfig.PaperFormats[0]?.Name
this.selectedProperties.paperid = this.selectedPrinterConfig.PaperFormats[0]?.Id
}
this.setPaperid()
}
Expand Down Expand Up @@ -717,31 +727,32 @@ export class EzpPrinterSelection {
}
preSelected={
this.selectedPrinter.id
? this.selectedProperties.color
? this.selectedPrinterConfig.Profile?.Color == "color"
? i18next.t('printer_selection.color_color')
: i18next.t('printer_selection.color_grayscale')
: null
}
disabled={!this.selectedPrinterConfig.Color}
disabled={!this.selectedPrinterConfig.ColorSupported}
/>
<ezp-select
label={i18next.t('printer_selection.duplex')}
icon="duplex"
placeholder={i18next.t('printer_selection.select_duplex')}
toggleFlow="horizontal"
options={this.duplexOptions.map((option) => ({
options={this.duplexOptions?.map((option) => ({
id: option.id,
title: option.title,
meta: '',
type: 'duplex',
}))}
preSelected={
this.selectedPrinter.id && this.selectedProperties.duplex
? this.duplexOptions.find(
(option) => option.id === this.selectedProperties.duplexmode
).id
: null
}
this.selectedPrinter.id && this.selectedPrinterConfig.Profile?.Duplex == "duplex_simplex"
? i18next.t('printer_selection.duplex_none')
: this.selectedPrinterConfig.Profile?.Duplex == "duplex_vertical"
? i18next.t('printer_selection.duplex_long')
: this.selectedPrinterConfig.Profile?.Duplex == "duplex_horizontal"
? i18next.t('printer_selection.duplex_short')
: null}
disabled={!this.selectedPrinterConfig.DuplexSupported}
/>
<ezp-select
Expand All @@ -750,14 +761,17 @@ export class EzpPrinterSelection {
placeholder={i18next.t('printer_selection.select_size')}
toggleFlow="horizontal"
optionFlow="horizontal"
options={this.selectedPrinterConfig.PaperFormats.map((format) => ({
options={this.selectedPrinterConfig.PaperFormats && this.selectedPrinterConfig.PaperFormats.map((format) => ({
id: format.Id,
title: format.Name,
meta: `${format.XRes} x ${format.YRes}`,
type: 'format',
}))}
preSelected={this.selectedPrinter.id ? this.selectedProperties.paper : null}
disabled={!(this.selectedPrinterConfig.PaperFormats.length > 0)}
preSelected={this.selectedPrinter.id && this.selectedPrinterConfig.PaperFormats?.find((el) =>
el.Name.includes(this.selectedPrinterConfig.Profile?.Paper))
? this.selectedPrinterConfig.Profile?.Paper
: null}
disabled={!(this.selectedPrinterConfig.PaperFormats?.length > 0)}
/>
{this.paperid == PAPER_ID ? (
<>
Expand Down Expand Up @@ -800,34 +814,41 @@ export class EzpPrinterSelection {
icon="quality"
placeholder={i18next.t('printer_selection.select_quality')}
toggleFlow="horizontal"
options={this.selectedPrinterConfig.Resolutions.map((option, index) => ({
options={this.selectedPrinterConfig.Resolutions?.map((option, index) => ({
id: index,
title: option,
meta: '',
type: 'quality',
}))}
preSelected={this.selectedPrinter.id ? this.selectedProperties.resolution : null}
disabled={!(this.selectedPrinterConfig.Resolutions.length > 0)}
preSelected={this.selectedPrinter.id && this.selectedPrinterConfig.Resolutions?.includes(this.selectedPrinterConfig.Profile.Resolution)
? this.selectedPrinterConfig.Profile.Resolution
: null}
disabled={!(this.selectedPrinterConfig.Resolutions?.length > 0)}
/>
{this.selectedPrinterConfig.Trays.length >= 1 && this.selectedPrinterConfig.Trays[0] != null ? (
{this.selectedPrinterConfig.Trays && this.selectedPrinterConfig.Trays.length >= 1 && this.selectedPrinterConfig.Trays[0] != null ? (
<ezp-select
label={i18next.t('printer_selection.trays')}
icon="trays"
placeholder={i18next.t('printer_selection.select_trays')}
toggleFlow="horizontal"
optionFlow="horizontal"
options={this.selectedPrinterConfig.Trays.length >= 1 && this.selectedPrinterConfig.Trays.map((trays) => ({
options={this.selectedPrinterConfig.Trays && this.selectedPrinterConfig.Trays.length >= 1 && this.selectedPrinterConfig.Trays.map((trays) => ({
title: trays.Name,
id: trays.Index,
meta: '',
type: 'tray',
}))}
})
)}
preSelected={this.selectedPrinter.id && this.selectedPrinterConfig.Trays?.find((el) =>
el.Name.includes(this.selectedPrinterConfig.Profile.Tray))
? this.selectedPrinterConfig.Profile.Tray
: null}
/> ) : null}
<ezp-input
icon="paper_range"
suffix=""
placeholder="1-2,4-5,8"
value={this.selectedProperties.PageRanges}
value={localStorage.getItem('pageRanges') ? this.selectedProperties.PageRanges : ''}
eventType="paper_ranges"
type="text"
label={i18next.t('printer_selection.page_ranges')}
Expand Down
17 changes: 11 additions & 6 deletions src/components/ezp-select/ezp-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ export class EzpSelect {
}
}

@Watch('preSelected')
preSelectedChanged() {
this.preSelect();
}

/**
*
* Private methods
Expand All @@ -134,7 +139,7 @@ export class EzpSelect {
}

private select = (id: number | string | boolean) => {
const delay = this.selected.id === id ? 0 : this.duration * 1000
const delay = this.selected?.id === id ? 0 : this.duration * 1000

this.selected = this.options.find((option) => option.id === id)
this.selectSelection.emit(this.selected)
Expand All @@ -145,7 +150,7 @@ export class EzpSelect {
}

private preSelect = () => {
this.selected = this.options.find((option) =>
this.selected = this.options?.find((option) =>
typeof this.preSelected === 'number'
? option.id === this.preSelected
: typeof this.preSelected === 'string'
Expand Down Expand Up @@ -185,7 +190,7 @@ export class EzpSelect {

componentWillUpdate() {
if (
this.selected.id === false &&
this.selected?.id === false &&
this.preSelected !== undefined &&
this.preSelected !== '' &&
this.preSelected !== null
Expand Down Expand Up @@ -219,16 +224,16 @@ export class EzpSelect {
<ezp-label
id="value"
ellipsis
text={this.selected.title !== '' ? this.selected.title : this.placeholder}
text={this.selected?.title !== '' ? this.selected?.title : this.placeholder}
/>
<ezp-icon id="accessory" name="expand" />
</div>
<div id="list" ref={(element) => (this.list = element)}>
{this.options.map((option) => {
{this.options?.map((option) => {
if (option.title !== '') {
return (
<div
class={`option ${option.id === this.selected.id ? 'is-selected' : ''} ${
class={`option ${option.id === this.selected?.id ? 'is-selected' : ''} ${
option.meta !== '' ? 'has-meta' : ''
} `}
onClick={() => this.select(option.id)}
Expand Down
1 change: 1 addition & 0 deletions src/components/ezp-upload/ezp-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class EzpUpload {
private handleInput = () => {
this.filename = this.input.files[0].name
this.uploadFile.emit(this.input.files)
localStorage.removeItem('pageRanges');
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface PaperFormat {
Name: string
XRes: number
YRes: number
Default: boolean
}

export interface Trays {
Expand All @@ -92,9 +93,10 @@ export interface Trays {
}

export interface PrinterConfig {
Preset?: {
Profile?: {
Duplex?: string
Color?: string
Orientation?: string
Resolution?: string
Paper?: string
Tray?: string
Expand Down

0 comments on commit 433d243

Please sign in to comment.