2019-05-01 14:58:58 +00:00
|
|
|
import { __ } from '~/locale';
|
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
export default class FilteredSearchTokenKeys {
|
2018-08-28 10:58:15 +00:00
|
|
|
constructor(tokenKeys = [], alternativeTokenKeys = [], conditions = []) {
|
|
|
|
this.tokenKeys = tokenKeys;
|
|
|
|
this.alternativeTokenKeys = alternativeTokenKeys;
|
|
|
|
this.conditions = conditions;
|
2017-01-24 20:03:39 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
this.tokenKeysWithAlternative = this.tokenKeys.concat(this.alternativeTokenKeys);
|
|
|
|
}
|
2016-12-13 04:15:31 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
get() {
|
|
|
|
return this.tokenKeys;
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2016-12-13 04:15:31 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
getKeys() {
|
2020-12-23 21:10:24 +00:00
|
|
|
return this.tokenKeys.map((i) => i.key);
|
2017-05-23 16:35:54 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
getAlternatives() {
|
|
|
|
return this.alternativeTokenKeys;
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2017-01-24 20:03:39 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
getConditions() {
|
|
|
|
return this.conditions;
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2016-12-15 18:54:24 +00:00
|
|
|
|
2018-10-03 08:15:00 +00:00
|
|
|
shouldUppercaseTokenName(tokenKey) {
|
|
|
|
const token = this.searchByKey(tokenKey.toLowerCase());
|
|
|
|
return token && token.uppercaseTokenName;
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldCapitalizeTokenValue(tokenKey) {
|
|
|
|
const token = this.searchByKey(tokenKey.toLowerCase());
|
|
|
|
return token && token.capitalizeTokenValue;
|
|
|
|
}
|
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
searchByKey(key) {
|
2020-12-23 21:10:24 +00:00
|
|
|
return this.tokenKeys.find((tokenKey) => tokenKey.key === key) || null;
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2016-12-13 04:15:31 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
searchBySymbol(symbol) {
|
2020-12-23 21:10:24 +00:00
|
|
|
return this.tokenKeys.find((tokenKey) => tokenKey.symbol === symbol) || null;
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2016-12-13 04:15:31 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
searchByKeyParam(keyParam) {
|
2018-10-10 06:18:49 +00:00
|
|
|
return (
|
2020-12-23 21:10:24 +00:00
|
|
|
this.tokenKeysWithAlternative.find((tokenKey) => {
|
2018-10-10 06:18:49 +00:00
|
|
|
let tokenKeyParam = tokenKey.key;
|
2016-12-16 16:22:09 +00:00
|
|
|
|
2018-10-10 06:18:49 +00:00
|
|
|
// Replace hyphen with underscore to compare keyParam with tokenKeyParam
|
|
|
|
// e.g. 'my-reaction' => 'my_reaction'
|
|
|
|
tokenKeyParam = tokenKeyParam.replace('-', '_');
|
2017-08-30 07:48:55 +00:00
|
|
|
|
2018-10-10 06:18:49 +00:00
|
|
|
if (tokenKey.param) {
|
|
|
|
tokenKeyParam += `_${tokenKey.param}`;
|
|
|
|
}
|
2016-12-16 16:22:09 +00:00
|
|
|
|
2018-10-10 06:18:49 +00:00
|
|
|
return keyParam === tokenKeyParam;
|
|
|
|
}) || null
|
|
|
|
);
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2016-12-13 04:15:31 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
searchByConditionUrl(url) {
|
2020-12-23 21:10:24 +00:00
|
|
|
return this.conditions.find((condition) => condition.url === url) || null;
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2016-12-13 04:15:31 +00:00
|
|
|
|
2020-01-02 13:03:23 +00:00
|
|
|
searchByConditionKeyValue(key, operator, value) {
|
2018-10-10 06:18:49 +00:00
|
|
|
return (
|
2019-01-28 08:59:58 +00:00
|
|
|
this.conditions.find(
|
2020-12-23 21:10:24 +00:00
|
|
|
(condition) =>
|
2020-01-02 13:03:23 +00:00
|
|
|
condition.tokenKey === key &&
|
|
|
|
condition.operator === operator &&
|
|
|
|
condition.value.toLowerCase() === value.toLowerCase(),
|
2019-01-28 08:59:58 +00:00
|
|
|
) || null
|
2018-10-10 06:18:49 +00:00
|
|
|
);
|
2016-11-30 18:30:52 +00:00
|
|
|
}
|
2018-10-03 08:15:00 +00:00
|
|
|
|
2019-02-25 11:00:24 +00:00
|
|
|
addExtraTokensForIssues() {
|
|
|
|
const confidentialToken = {
|
2020-01-02 13:03:23 +00:00
|
|
|
formattedKey: __('Confidential'),
|
2019-02-25 11:00:24 +00:00
|
|
|
key: 'confidential',
|
|
|
|
type: 'string',
|
|
|
|
param: '',
|
|
|
|
symbol: '',
|
|
|
|
icon: 'eye-slash',
|
2019-05-01 14:58:58 +00:00
|
|
|
tag: __('Yes or No'),
|
2019-02-25 11:00:24 +00:00
|
|
|
lowercaseValueOnSubmit: true,
|
|
|
|
uppercaseTokenName: false,
|
|
|
|
capitalizeTokenValue: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.tokenKeys.push(confidentialToken);
|
|
|
|
this.tokenKeysWithAlternative.push(confidentialToken);
|
|
|
|
}
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|