Skip to content

Commit eeff7b1

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 7d4903f + 855ebe7 commit eeff7b1

19 files changed

+160
-84
lines changed

.eslintrc.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ module.exports = {
1919
"no-tabs": 0,
2020
"max-len": 0,
2121
"linebreak-style": 0,
22-
"quote-props": ["warn", "consistent-as-needed", {"numbers": false}],
22+
"quote-props": ["warn", "consistent-as-needed", {
23+
"numbers": false
24+
}],
2325
"no-trailing-spaces": ["error", {
2426
"skipBlankLines": true,
2527
"ignoreComments": true
@@ -31,8 +33,13 @@ module.exports = {
3133
"named": "never",
3234
"asyncArrow": "always"
3335
}],
34-
"object-curly-spacing": 0,
36+
"object-curly-spacing": ["error", "always"],
37+
"object-property-newline": ["error", {
38+
"allowAllPropertiesOnSameLine": false
39+
}],
3540
"new-cap": 0,
36-
"no-useless-catch": "error"
41+
"no-useless-catch": "error",
42+
"arrow-spacing": 2,
43+
"camelcase": "error"
3744
}
3845
};

app/data.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ exports.wear = {
11291129
'4': '(Well-Worn)',
11301130
'5': '(Battle Scarred)'
11311131
};
1132+
11321133
exports.ETradeOfferState = {
11331134
Invalid: 1,
11341135
Active: 2, // This trade offer has been sent, neither party has acted on it yet.
@@ -1154,6 +1155,7 @@ exports.ETradeOfferState = {
11541155
10: 'CanceledBySecondFactor',
11551156
11: 'InEscrow'
11561157
};
1158+
11571159
exports.qualityColors = {
11581160
0: '#B2B2B2',
11591161
1: '#4D7455',
@@ -1203,3 +1205,8 @@ exports.paintCanColors = {
12031205
'5036;6': '7c6c57', // Ye Olde Rustic Colour
12041206
'5028;6': '424f3b' // Zepheniah's Greed
12051207
};
1208+
1209+
exports.defindexes = {
1210+
'Mann Co. Supply Crate Key': 5021,
1211+
'Lugermorph': 160
1212+
};

app/profit.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ exports.get = async function get(start, interval, end, enableTrades) {
2424
}
2525
);
2626
const keyVal = response.data.sell.metal;
27-
const trades = Object.keys(polldata.offerData).map((key)=>{
27+
const trades = Object.keys(polldata.offerData).map((key) => {
2828
const ret = polldata.offerData[key];
2929
ret.time = polldata.timestamps[key];
3030
ret.id = key;
@@ -34,7 +34,7 @@ exports.get = async function get(start, interval, end, enableTrades) {
3434

3535
const tracker = new itemTracker(start, interval, end, keyVal);
3636

37-
trades.sort((a, b)=>{
37+
trades.sort((a, b) => {
3838
a = a.time;
3939
b = b.time;
4040

@@ -120,14 +120,14 @@ exports.get = async function get(start, interval, end, enableTrades) {
120120
overpriceProfit += tracker.convert(trade.value.their, trade.value.rate) - tracker.convert(trade.value.our, trade.value.rate);
121121
tracker.profitTrack.countProfit( tracker.convert(trade.value.their, trade.value.rate) - tracker.convert(trade.value.our, trade.value.rate), trade.time);
122122
}
123-
tradeProfits[trade.id] = tracker.profitTrack.getFormated(tradeProfit);
123+
tradeProfits[trade.id] = tracker.profitTrack.getFormatted(tradeProfit);
124124
}
125125
const returnObj = {
126-
profitTotal: tracker.profitTrack.getFormated(tracker.profitTrack.profit),
127-
profitTimed: tracker.profitTrack.getFormated(tracker.profitTrack.profitTimed),
126+
profitTotal: tracker.profitTrack.getFormatted(tracker.profitTrack.profit),
127+
profitTimed: tracker.profitTrack.getFormatted(tracker.profitTrack.profitTimed),
128128
profitPlot: tracker.profitTrack.profitPlot,
129129
numberOfTrades: iter,
130-
overpriceProfit: tracker.profitTrack.getFormated(overpriceProfit),
130+
overpriceProfit: tracker.profitTrack.getFormatted(overpriceProfit),
131131
keyValue: keyVal
132132
};
133133
if (enableTrades) returnObj['tradeProfits'] = tradeProfits;
@@ -174,13 +174,13 @@ class profitTracker {
174174
this.profitPlot.push({
175175
time: lastTradePlotBlock*this.interval + this.start,
176176
profit: this.tempProfit,
177-
formated: this.getFormated(this.tempProfit)
177+
formatted: this.getFormatted(this.tempProfit)
178178
});
179179
for (let i = lastTradePlotBlock+1; i < thisTradePlotBlock; i++) { // create block even if no trades happend
180180
this.profitPlot.push({
181181
time: i*this.interval + this.start,
182182
profit: 0,
183-
formated: this.getFormated(0)
183+
formatted: this.getFormatted(0)
184184
});
185185
}
186186
this.tempProfit = normalizedAmount; // reset temp to value of current trade
@@ -194,7 +194,7 @@ class profitTracker {
194194
this.profitPlot.push({
195195
time: lastTradePlotBlock*this.interval + this.start,
196196
profit: this.tempProfit,
197-
formated: this.getFormated(this.tempProfit)
197+
formatted: this.getFormatted(this.tempProfit)
198198
});
199199
this.tempProfit = 0;
200200
}
@@ -203,15 +203,18 @@ class profitTracker {
203203
/**
204204
*
205205
* @param {Number} normalPrice
206-
* @return {String} formated string
206+
* @return {String} formatted string
207207
*/
208-
getFormated(normalPrice) {
208+
getFormatted(normalPrice) {
209209
const key = new Currency({
210210
metal: this.currentKey
211211
}).toValue(this.currentKey); // get value in scrap
212212
const metal = Currency.toRefined(normalPrice % key);
213213
const keys = normalPrice>0 ? Math.floor(normalPrice / key) : Math.ceil(normalPrice / key);
214-
return new Currency({keys, metal}).toString();
214+
return new Currency({
215+
keys,
216+
metal
217+
}).toString();
215218
}
216219
}
217220
/**

app/routes/addItem.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ router.post('/', (req, res) => {
3232
let sellvalues;
3333
let buyvalues;
3434
if (!autopriced) {
35-
sellvalues = new Currency({ keys: sellkeys, metal: sellmetal}).toJSON();
36-
buyvalues = new Currency({ keys: buykeys, metal: buymetal}).toJSON();
35+
sellvalues = new Currency({
36+
keys: sellkeys,
37+
metal: sellmetal
38+
}).toJSON();
39+
40+
buyvalues = new Currency({
41+
keys: buykeys,
42+
metal: buymetal
43+
}).toJSON();
3744

3845
// lower sell keys
3946
if (sellvalues.keys < buyvalues.keys && intent != 0) {

app/routes/addItems.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,15 @@ router.post('/', (req, res) => {
4141
});
4242

4343
if (!req.body.autoprice) {
44-
sellvalues = { keys: Number(req.body.sell_keys), metal: Number(req.body.sell_metal)};
45-
buyvalues = { keys: Number(req.body.buy_keys), metal: Number(req.body.buy_metal)};
44+
sellvalues = {
45+
keys: Number(req.body.sell_keys),
46+
metal: Number(req.body.sell_metal)
47+
};
48+
49+
buyvalues = {
50+
keys: Number(req.body.buy_keys),
51+
metal: Number(req.body.buy_metal)
52+
};
4653

4754
// lower sell keys
4855
if (sellvalues.keys < buyvalues.keys && req.body.intent != 0) {

app/routes/changeItem.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Currency = require('tf2-currencies');
44
const pricelist = require('../pricelist');
55

66
router.post('/', (req, res) => {
7-
const { sku, intent, autoprice, min, max, sellkeys, sellmetal, buykeys, buymetal, enabled} = req.body;
7+
const { sku, intent, autoprice, min, max, sellkeys, sellmetal, buykeys, buymetal, enabled } = req.body;
88
if (parseInt(max) < parseInt(min)) {
99
res.json({
1010
success: 0,
@@ -16,8 +16,15 @@ router.post('/', (req, res) => {
1616
return;
1717
}
1818

19-
const sellvalues = new Currency({keys: sellkeys, metal: sellmetal}).toJSON();
20-
const buyvalues = new Currency({keys: buykeys, metal: buymetal}).toJSON();
19+
const sellvalues = new Currency({
20+
keys: sellkeys,
21+
metal: sellmetal
22+
}).toJSON();
23+
24+
const buyvalues = new Currency({
25+
keys: buykeys,
26+
metal: buymetal
27+
}).toJSON();
2128

2229
// lower sell keys
2330
if (!autoprice) {

app/routes/trades.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ router.get('/', (req, res) => {
2525
return;
2626
}
2727

28-
trades.get(Number(req.query.first), Number(req.query.count), Number(req.query.dir)==1)
28+
trades.get(Number(req.query.first), Number(req.query.count), Number(req.query.dir)==1, req.query.search)
2929
.then((data) => {
3030
res.json({
3131
success: 1,

app/trades.js

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ const profit = require('./profit');
1111
* @param {Number} first index of first trade to be included in results
1212
* @param {Number} count how many trades to include in results, set to -1 to return all
1313
* @param {Boolean} descending sort
14+
* @param {String} search string to search listings for
1415
*/
15-
exports.get = async function(first, count, descending) {
16+
exports.get = async function(first, count, descending, search) {
17+
search = search.trim().toLowerCase();
1618
const polldata = await fs.readJSON(paths.files.polldata);
1719
const profitData = (await profit.get(undefined, undefined, undefined, true)).tradeProfits;
18-
let tradeList = Object.keys(polldata.offerData).map((key)=>{
20+
let tradeList = Object.keys(polldata.offerData).map((key) => {
1921
const ret = polldata.offerData[key];
2022
ret.id = key;
2123
return ret;
2224
});
2325
const tradeCount = tradeList.length;
24-
tradeList = tradeList.sort((a, b)=>{
26+
tradeList = tradeList.sort((a, b) => {
2527
a = a.finishTimestamp;
2628
b = b.finishTimestamp;
2729

@@ -30,15 +32,25 @@ exports.get = async function(first, count, descending) {
3032
if ( !(!a || isNaN(a)) && (!b || isNaN(b))) return -1;
3133
if ( (!a || isNaN(a)) && (!b || isNaN(b))) return 0;
3234

33-
if (descending) {
34-
b = [a, a = b][0];
35-
}
35+
if (descending) b = [a, a = b][0];
3636

3737
return a - b;
3838
});
39+
tradeList = tradeList.filter((offer) => {
40+
let offerSearchResults = false;
41+
if (Object.prototype.hasOwnProperty.call(offer, 'dict')) {
42+
offerSearchResults = Object.keys(offer.dict.our).reduce((accumulator, item) => {
43+
return accumulator || getName(item).toLowerCase().indexOf(search) > -1;
44+
}, false);
45+
offerSearchResults |= Object.keys(offer.dict.our).reduce((accumulator, item) => {
46+
return accumulator || getName(item).toLowerCase().indexOf(search) > -1;
47+
}, false);
48+
}
49+
return offer.id.indexOf(search) > -1 || offerSearchResults;
50+
});
3951
if (count != -1) tradeList = tradeList.slice(first, first + count);
4052
const items = {};
41-
const trades = tradeList.map((offer)=>{
53+
const trades = tradeList.map((offer) => {
4254
const ret = {
4355
id: offer.id,
4456
items: {
@@ -53,36 +65,30 @@ exports.get = async function(first, count, descending) {
5365
value: offer.value,
5466
accepted: offer.handledByUs === true && offer.isAccepted === true
5567
};
56-
if (typeof polldata.sent[offer.id] != 'undefined') {
57-
ret.lastState = data.ETradeOfferState[polldata.sent[offer.id]];
58-
} else if (typeof polldata.received[offer.id] != 'undefined') {
59-
ret.lastState = data.ETradeOfferState[polldata.received[offer.id]];
60-
}
68+
69+
if (typeof polldata.sent[offer.id] != 'undefined') ret.lastState = data.ETradeOfferState[polldata.sent[offer.id]];
70+
else if (typeof polldata.received[offer.id] != 'undefined') ret.lastState = data.ETradeOfferState[polldata.received[offer.id]];
71+
6172
if (Object.prototype.hasOwnProperty.call(offer, 'dict')) {
62-
if (Object.keys(offer.dict.our).length > 0) {
63-
Object.keys(offer.dict.our).forEach((k)=>{
64-
if (!Object.prototype.hasOwnProperty.call(items, k)) {
65-
items[k] = createTradeItem(k);
66-
}
67-
ret.items.our.push({
68-
sku: k,
69-
amount: offer.dict.our[k]
70-
});
71-
});
72-
}
73-
if (Object.keys(offer.dict.their).length > 0) {
74-
Object.keys(offer.dict.their).forEach((k)=>{
75-
if (!Object.prototype.hasOwnProperty.call(items, k)) {
76-
items[k] = createTradeItem(k);
77-
}
78-
ret.items.their.push({
79-
sku: k,
80-
amount: offer.dict.their[k]
81-
});
82-
});
83-
}
73+
if (Object.keys(offer.dict.our).length > 0) tradeSide('our');
74+
if (Object.keys(offer.dict.their).length > 0) tradeSide('their');
8475
}
76+
8577
return ret;
78+
79+
/**
80+
* Get items from one side of a trade
81+
* @param {'our'|'their'} side
82+
*/
83+
function tradeSide(side) {
84+
Object.keys(offer.dict[side]).forEach((k) => {
85+
if (!Object.prototype.hasOwnProperty.call(items, k)) items[k] = createTradeItem(k);
86+
ret.items[side].push({
87+
sku: k,
88+
amount: offer.dict[side][k]
89+
});
90+
});
91+
}
8692
});
8793
return {
8894
trades,

assets/css/index.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
position: relative;
1010
}
1111
.info {
12+
line-height: 1.2;
1213
position:relative;
1314
z-index: 1000;
1415
width: 100%;
@@ -102,13 +103,21 @@
102103
left: 2px;
103104
position: absolute;
104105
z-index: 2;
106+
-webkit-user-select: none; /* Safari */
107+
-moz-user-select: none; /* Firefox */
108+
-ms-user-select: none; /* IE10+/Edge */
109+
user-select: none; /* Standard */
105110
}
106111
.item-grid .autoprice-symbol {
107112
top: 2px;
108113
right: 2px;
109114
position: absolute;
110115
z-index: 2;
111116
color: #29a30e;
117+
-webkit-user-select: none; /* Safari */
118+
-moz-user-select: none; /* Firefox */
119+
-ms-user-select: none; /* IE10+/Edge */
120+
user-select: none; /* Standard */
112121
}
113122
.item-list .autoprice-symbol {
114123
color: #29a30e;
@@ -123,4 +132,24 @@
123132
.item-list{
124133
width: 100%;
125134
height: 64px;
135+
}
136+
.price {
137+
line-height: 1.3;
138+
font-size: small;
139+
position: absolute;
140+
bottom: 0;
141+
z-index: 1001;
142+
width: 100%;
143+
visibility: hidden;
144+
background-color:rgba(255, 255, 255, 0.7);
145+
overflow-x: wrap;
146+
overflow-y: hidden;
147+
-webkit-user-select: none; /* Safari */
148+
-moz-user-select: none; /* Firefox */
149+
-ms-user-select: none; /* IE10+/Edge */
150+
user-select: none; /* Standard */
151+
background-color: #666;
152+
}
153+
.item:hover .price {
154+
visibility: visible;
126155
}

assets/js/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const app = new Vue({
205205
url: '/addItems',
206206
data: postData
207207
})
208-
.then((resp)=>{
208+
.then((resp) => {
209209
app.sendMessage(resp.data.msg.type, resp.data.msg.message);
210210
app.loadItems();
211211
});

0 commit comments

Comments
 (0)