Skip to content

Commit aa98bfd

Browse files
author
Jan Kotrlik
authored
Add serial id into category listing, remove unused columns (#191)
* Add serial id into category listing, remove unused columns * Fix eslint, tune node version
1 parent 97a397e commit aa98bfd

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
build:
44
docker:
5-
- image: circleci/node:10
5+
- image: circleci/node:14.16.1
66
working_directory: ~/siros-postgres
77
steps:
88
- checkout

admin-scripts/lib/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const config = {
9595
// limits for display column widths
9696
descriptionWidth: 65,
9797
commentWidth: 34,
98+
serialIdWidth: 30,
9899
},
99100

100101
hwItems: {

admin-scripts/lib/db-query.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ class DbQuery extends Db {
380380
.field('h.active', 'active')
381381
.field('h.available', 'available')
382382
.field('h.comment', 'comment')
383+
.field('h.serial_id', 'serial_id')
383384
.from('hw', 'h')
384385
.join('hw_categories', 'c', 'h.category = c.id')
385386
.join('stores', 's', 'h.store = s.id')

admin-scripts/lib/dialog-hw.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,24 @@ const printStores = (stores) => {
104104
const printHw = (hw) => {
105105
const descrWidthMax = config.hwDisplay.descriptionWidth;
106106
const commentWidthMax = config.hwDisplay.commentWidth;
107+
const serialIdWidthMax = config.hwDisplay.serialIdWidth;
107108
let idWidth = 3;
108109
let categoryWidth = 9;
109110
let descrWidth = 6;
110-
let storeWidth = 6;
111+
const purchDateWidth = 10;
111112
let priceWidth = 6;
112113
let curPriceWidth = 10;
113114
let condWidth = 5;
114115
let userWidth = 5;
115-
let maxWidth = 4;
116116
let commentWidth = 8;
117+
let serialIdWidth = 8;
117118

118119
const today = (new Date()).toISOString().substr(0, 10);
119120
let len;
120121
let i;
121122
hw.forEach((item) => {
122123
//
123124
let price = config.hwItems.getAgedPrice(item.purchase_price, item.purchase_date, today);
124-
if (item.max_price !== null) { price = Math.min(item.max_price, price); }
125125
if (item.condition === 'new') { price = item.purchase_price; }
126126
item.current_price_calc = price;
127127
//
@@ -131,8 +131,6 @@ const printHw = (hw) => {
131131
if (len > categoryWidth) { categoryWidth = len; }
132132
len = item.description ? Math.min(descrWidthMax, item.description.length) : 0;
133133
if (len > descrWidth) { descrWidth = len; }
134-
len = item.store.length;
135-
if (len > storeWidth) { storeWidth = len; }
136134
len = item.purchase_price.toString().length;
137135
if (len > priceWidth) { priceWidth = len; }
138136
len = item.current_price_calc.toString().length;
@@ -141,15 +139,15 @@ const printHw = (hw) => {
141139
if (len > condWidth) { condWidth = len; }
142140
len = item.user.length;
143141
if (len > userWidth) { userWidth = len; }
144-
len = item.max_price !== null ? item.max_price.toString().length : 0;
145-
if (len > maxWidth) { maxWidth = len; }
142+
len = item.serial_id !== null ? Math.min(serialIdWidthMax, item.serial_id.length) : 0;
143+
if (len > serialIdWidth) { serialIdWidth = len; }
146144
len = item.comment ? Math.min(commentWidthMax, item.comment.length) : 0;
147145
if (len > commentWidth) { commentWidth = len; }
148146
});
149147
let str = printf(
150-
` %-${idWidth}s | A | M | %-${condWidth}s | %-${categoryWidth}s | %-${descrWidth}s | %-${storeWidth}s | `
151-
+ `pur. date: | %-${priceWidth}s | %-${curPriceWidth}s | %-${maxWidth}s | %-${userWidth}s | comment:\n`,
152-
'id:', 'cond:', 'category:', 'descr:', 'store:', 'price:', 'cur.price:', 'max:', 'user:',
148+
` %-${idWidth}s | A | M | %-${condWidth}s | %-${categoryWidth}s | %-${descrWidth}s | `
149+
+ `pur. date: | %-${priceWidth}s | %-${curPriceWidth}s | %-${userWidth}s | %-${serialIdWidth}s | comment:\n`,
150+
'id:', 'cond:', 'category:', 'descr:', 'price:', 'cur.price:', 'user:', 'serial_id:',
153151
);
154152
process.stdout.write(str);
155153
str = '-';
@@ -161,16 +159,16 @@ const printHw = (hw) => {
161159
str += '-+-';
162160
for (i = 0; i < descrWidth; i += 1) { str += '-'; }
163161
str += '-+-';
164-
for (i = 0; i < storeWidth; i += 1) { str += '-'; }
165-
str += '-+------------+-';
162+
for (i = 0; i < purchDateWidth; i += 1) { str += '-'; }
163+
str += '-+-';
166164
for (i = 0; i < priceWidth; i += 1) { str += '-'; }
167165
str += '-+-';
168166
for (i = 0; i < curPriceWidth; i += 1) { str += '-'; }
169167
str += '-+-';
170-
for (i = 0; i < maxWidth; i += 1) { str += '-'; }
171-
str += '-+-';
172168
for (i = 0; i < userWidth; i += 1) { str += '-'; }
173169
str += '-+-';
170+
for (i = 0; i < serialIdWidth; i += 1) { str += '-'; }
171+
str += '-+-';
174172
for (i = 0; i < commentWidth; i += 1) { str += '-'; }
175173
str += '-\n';
176174
process.stdout.write(str);
@@ -182,13 +180,16 @@ const printHw = (hw) => {
182180
const comment = item.comment
183181
? (item.comment.length <= commentWidthMax ? item.comment : `${item.comment.substr(0, commentWidthMax - 3)}...`)
184182
: '';
183+
const serialId = item.serial_id
184+
? (item.serial_id.length <= serialIdWidthMax ? item.serial_id : `${item.serial_id.substr(0, serialIdWidthMax - 3)}...`)
185+
: '';
185186
str = printf(
186-
` %${idWidth}s | %s | %s | %-${condWidth}s | %-${categoryWidth}s | %-${descrWidth}s | %-${storeWidth}s | `
187-
+ `%s | %${priceWidth}s | %${curPriceWidth}s | %${maxWidth}s | %-${userWidth}s | %s\n`,
187+
` %${idWidth}s | %s | %s | %-${condWidth}s | %-${categoryWidth}s | %-${descrWidth}s | `
188+
+ `%s | %${priceWidth}s | %${curPriceWidth}s | %-${userWidth}s | %-${serialIdWidth}s | %s\n`,
188189
item.id.toString(), item.active ? 'x' : ' ', item.available ? 'x' : ' ', item.condition, item.category, descr,
189-
item.store, item.purchase_date, item.purchase_price.toString(),
190-
item.active ? item.current_price_calc.toString() : '', item.max_price !== null ? item.max_price.toString() : '',
191-
item.user, comment,
190+
item.purchase_date, item.purchase_price.toString(),
191+
item.active ? item.current_price_calc.toString() : '',
192+
item.user, serialId, comment,
192193
);
193194
process.stdout.write(str);
194195
});

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
},
1313
"author": "Roman Kaspar <[email protected]> (https://salsitasoft.com/)",
1414
"repository": "[email protected]:salsita/siros-postgres.git",
15-
"license": "MIT"
15+
"license": "MIT",
16+
"engines": {
17+
"node": "14.16.1"
18+
}
1619
}

0 commit comments

Comments
 (0)