Skip to content

Commit

Permalink
Resolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
tp-teman committed Dec 15, 2023
2 parents a860373 + 4ba1af0 commit ad89f80
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export namespace Components {
* Description...
*/
"label": string;
/**
* Description...
*/
"placeholder": string;
/**
* Description...
*/
Expand Down Expand Up @@ -460,6 +464,10 @@ declare namespace LocalJSX {
* Events
*/
"onInputValueChanged"?: (event: CustomEvent<any>) => void;
/**
* Description...
*/
"placeholder"?: string;
/**
* Description...
*/
Expand Down
6 changes: 5 additions & 1 deletion src/components/ezp-input/ezp-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export class EzpInput {
/** Description... */
@Prop() eventType: string

/** Description... */
@Prop() placeholder: string = ''


/**
*
Expand All @@ -54,7 +57,7 @@ export class EzpInput {
if (this.timeout) {
clearTimeout(this.timeout)
}
this.value = event.target.value ? event.target.value : 0
this.value = event.target.value ? event.target.value : this.type === 'number' ? 0 : ''
this.timeout = setTimeout(() => {
this.inputValueChanged.emit({
type: this.eventType.toLowerCase(),
Expand Down Expand Up @@ -84,6 +87,7 @@ export class EzpInput {
id="input"
type={this.type}
value={this.value}
placeholder={this.placeholder}
onInput={(event) => this.handleChange(event)}
ref={(input) => (this.input = input)}
onFocus={this.handleFocus}
Expand Down
28 changes: 24 additions & 4 deletions src/components/ezp-printer-selection/ezp-printer-selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import userStore, { EzpUserService } from '../../services/user'
import { Printer, PrinterConfig, PrinterProperties } from '../../shared/types'
import { managePaperDimensions, poll, removeEmptyStrings } from '../../utils/utils'
import { BlobUploadCommonResponse } from '@azure/storage-blob'
import { PAPER_ID } from '../../utils/utils'
import { PAPER_ID , validatePageRange , formatPageRange } from '../../utils/utils'

@Component({
tag: 'ezp-printer-selection',
Expand Down Expand Up @@ -66,6 +66,7 @@ export class EzpPrinterSelection {
*/
@State() loading: boolean = true
@State() printProcessing: boolean = false
@State() pageRangeInvalid: boolean = false
@State() uploading: boolean = false
@State() preparingUpload: boolean = false
@State() printSuccess: boolean = false
Expand Down Expand Up @@ -100,7 +101,8 @@ export class EzpPrinterSelection {
paperlength : 0,
paperwidth : 0,
defaultSource: '',
trayname: ''
trayname: '',
PageRanges : '',
}

@State() paperid: number | string
Expand Down Expand Up @@ -222,8 +224,11 @@ export class EzpPrinterSelection {
delete this.selectedProperties.trayname
delete this.selectedProperties.defaultSource
}
let cleanPrintProperties = removeEmptyStrings(this.selectedProperties)
let cleanPrintProperties: PrinterProperties = removeEmptyStrings(this.selectedProperties)
cleanPrintProperties = managePaperDimensions(cleanPrintProperties)
if (cleanPrintProperties.PageRanges)
cleanPrintProperties.PageRanges = formatPageRange(cleanPrintProperties.PageRanges)

// put it in store for further use
printStore.state.fileUrl = this.fileurl
printStore.state.fileID = this.fileid
Expand Down Expand Up @@ -393,6 +398,12 @@ export class EzpPrinterSelection {
this.selectedProperties.defaultSource = eventDetails.id
}
break
case 'paper_ranges':
this.selectedProperties.PageRanges = eventDetails.value;
this.pageRangeInvalid = !validatePageRange(this.selectedProperties.PageRanges);

// console.log(this.selectedProperties.PageRanges)
break
case 'duplex':
if (eventDetails.title === 'None') {
this.selectedProperties.duplex = false
Expand Down Expand Up @@ -812,6 +823,15 @@ export class EzpPrinterSelection {
type: 'tray',
}))}
/> ) : null}
<ezp-input
icon="width"
suffix=""
placeholder="1-2,4-5,8"
value={this.selectedProperties.PageRanges}
eventType="paper_ranges"
type="text"
label={i18next.t('printer_selection.paper_ranges')}
/>
</div>
<ezp-stepper label={i18next.t('printer_selection.copies')} max={10} icon="copies" />
</div>
Expand All @@ -825,7 +845,7 @@ export class EzpPrinterSelection {
id="cancel"
/>
<ezp-text-button
disabled={this.selectedPrinter.id === '' || this.printProcessing}
disabled={this.selectedPrinter.id === '' || this.printProcessing || this.pageRangeInvalid}
type="button"
onClick={this.handlePrint}
label={i18next.t('button_actions.print')}
Expand Down
3 changes: 2 additions & 1 deletion src/data/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"length":"Länge",
"trays": "Trays",
"select_trays": "Wähle Trays",
"page_ranges": "Page Ranges"
"page_ranges": "Page Ranges",
"paper_ranges": "Papier-Ranges"
},
"button_actions": {
"login": "Anmelden",
Expand Down
3 changes: 2 additions & 1 deletion src/data/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"length":"Length",
"trays": "Trays",
"select_trays": "Select Trays",
"page_ranges": "Page Ranges"
"page_ranges": "Page Ranges",
"paper_ranges": "Paper Ranges"
},
"button_actions": {
"login": "Sign In",
Expand Down
1 change: 1 addition & 0 deletions src/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface PrinterProperties {
paperwidth? : string | number
defaultSource?: number | string
trayname?: string
PageRanges? : string
}

export interface Printer {
Expand Down
33 changes: 33 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,37 @@ export const managePaperDimensions = (properties :PrinterProperties)=>{
return properties
}

export const formatPageRange = (pageRange) => {
return pageRange.replace(/,/g, ';')
}

export const validatePageRange = (pageRange) => {
if (!pageRange) {
return true
}
const regex = /^(\d+(-\d+)?(,\d+(-\d+)?)*|(\d+,\d+(-\d+)?(,\d+(-\d+)?)*)+)$/;
const isValid = regex.test(pageRange);
if (!isValid) {
return false
}
let ranges = pageRange.split(',');
for (let i = 0; i < ranges.length; i++) {
let rng = ranges[i].trim();
if (rng.includes('-')) {
let [start, end] = rng.split('-');
start = parseInt(start);
end = parseInt(end);
if (isNaN(start) || isNaN(end) || start > end || start <= 0) {
return false;
}
} else {
let page = parseInt(rng);
if (isNaN(page) || page <= 0) {
return false
}
}
}
return true
}

export const PAPER_ID = 256

0 comments on commit ad89f80

Please sign in to comment.