|
| 1 | +polarity.export = PolarityComponent.extend({ |
| 2 | + // Hides the filter menu by default |
| 3 | + viewFilters: false, |
| 4 | + // This is the initial view limit. The user can view up to 10 by clicking on a "view more" action link |
| 5 | + viewLimit: 5, |
| 6 | + // Stores any error messages from our onMessage hook |
| 7 | + errorMessage: '', |
| 8 | + infoMessage: '', |
| 9 | + details: Ember.computed.alias('block.data.details'), |
| 10 | + searchResults: Ember.computed.alias('details.searchResults'), |
| 11 | + searchInformation: Ember.computed.alias('searchResults.searchInformation'), |
| 12 | + icons: Ember.computed.alias('details.icons'), |
| 13 | + searchFilters: Ember.computed.alias('block.storage.searchFilters'), |
| 14 | + numSourcesToSearch: Ember.computed.alias('block.storage.numSourcesToSearch'), |
| 15 | + init: function () { |
| 16 | + this._super(...arguments); |
| 17 | + if (!this.get('block.storage.searchFilters')) { |
| 18 | + this.set('block.storage', {}); |
| 19 | + this.set('block.storage.searchFilters', [ |
| 20 | + { |
| 21 | + displayValue: 'app.any.run', |
| 22 | + filterValue: 'app.any.run', |
| 23 | + id: 'app-checkbox', |
| 24 | + value: true |
| 25 | + }, |
| 26 | + { |
| 27 | + displayValue: 'any.run', |
| 28 | + filterValue: 'any.run', |
| 29 | + id: 'any-checkbox', |
| 30 | + value: true |
| 31 | + }, |
| 32 | + { |
| 33 | + displayValue: 'VirusTotal', |
| 34 | + filterValue: 'virustotal.com', |
| 35 | + id: 'vt-checkbox', |
| 36 | + value: true |
| 37 | + }, |
| 38 | + { |
| 39 | + displayValue: 'Joe Sandbox', |
| 40 | + filterValue: 'joesandbox.com', |
| 41 | + id: 'js-checkbox', |
| 42 | + value: true |
| 43 | + }, |
| 44 | + { |
| 45 | + displayValue: 'Intezer', |
| 46 | + filterValue: 'analyze.intezer.com', |
| 47 | + id: 'intezer-checkbox', |
| 48 | + value: true |
| 49 | + }, |
| 50 | + { |
| 51 | + displayValue: 'Hybrid Analysis', |
| 52 | + filterValue: 'hybrid-analysis.com', |
| 53 | + id: 'ha-checkbox', |
| 54 | + value: true |
| 55 | + }, |
| 56 | + { |
| 57 | + displayValue: 'Valkyrie Comodo', |
| 58 | + filterValue: 'valkyrie.comodo.com', |
| 59 | + id: 'comodo-checkbox', |
| 60 | + value: true |
| 61 | + }, |
| 62 | + { |
| 63 | + displayValue: 'IRIS-H', |
| 64 | + filterValue: 'iris-h.services', |
| 65 | + id: 'irish-checkbox', |
| 66 | + value: true |
| 67 | + }, |
| 68 | + { |
| 69 | + displayValue: 'Labs.Inquest', |
| 70 | + filterValue: 'labs.inquest.net', |
| 71 | + id: 'inquest-checkbox', |
| 72 | + value: true |
| 73 | + }, |
| 74 | + { |
| 75 | + displayValue: 'Manalyzer', |
| 76 | + filterValue: 'manalyzer.org', |
| 77 | + id: 'manalyzer-checkbox', |
| 78 | + value: true |
| 79 | + }, |
| 80 | + { |
| 81 | + displayValue: 'Sandbox Pikker', |
| 82 | + filterValue: 'sandbox.pikker.ee', |
| 83 | + id: 'pikker-checkbox', |
| 84 | + value: true |
| 85 | + }, |
| 86 | + { |
| 87 | + displayValue: 'Yomi Yoroi', |
| 88 | + filterValue: 'yomi.yoroi.company', |
| 89 | + id: 'yomi-checkbox', |
| 90 | + value: true |
| 91 | + } |
| 92 | + ]); |
| 93 | + this.set('block.storage.numSourcesToSearch', this.get('block.storage.searchFilters.length')); |
| 94 | + } |
| 95 | + }, |
| 96 | + actions: { |
| 97 | + toggleFilter: function () { |
| 98 | + this.toggleProperty('viewFilters'); |
| 99 | + }, |
| 100 | + applyFilter: function () { |
| 101 | + this.set('errorMessage', ''); |
| 102 | + this.set('infoMessage', ''); |
| 103 | + |
| 104 | + const numSourcesToSearch = this.getNumSourcesSearched(); |
| 105 | + if (numSourcesToSearch === 0) { |
| 106 | + this.set('infoMessage', 'Select at least one source to search'); |
| 107 | + return; |
| 108 | + } |
| 109 | + this.set('filtering', true); |
| 110 | + const payload = { |
| 111 | + entity: this.block.entity, |
| 112 | + searchFilters: this.searchFilters |
| 113 | + }; |
| 114 | + |
| 115 | + this.sendIntegrationMessage(payload) |
| 116 | + .then((searchResults) => { |
| 117 | + this.set('block.data.details.searchResults', searchResults); |
| 118 | + }) |
| 119 | + .catch((err) => { |
| 120 | + console.error(err); |
| 121 | + if (typeof err.meta === 'string') { |
| 122 | + this.set('errorMessage', err.meta); |
| 123 | + } else if (typeof err.meta === 'object' && typeof err.meta.error === 'string') { |
| 124 | + this.set('errorMessage', err.meta.error); |
| 125 | + } else if (typeof err.meta === 'object' && typeof err.meta.detail === 'string') { |
| 126 | + this.set('errorMessage', err.meta.detail); |
| 127 | + } else { |
| 128 | + this.set('errorMessage', JSON.stringify(err.meta)); |
| 129 | + } |
| 130 | + }) |
| 131 | + .finally(() => { |
| 132 | + this.set('numSourcesToSearch', numSourcesToSearch); |
| 133 | + this.set('filtering', false); |
| 134 | + }); |
| 135 | + }, |
| 136 | + selectAll: function () { |
| 137 | + for (let i = 0; i < this.searchFilters.length; i++) { |
| 138 | + this.set(`searchFilters.${i}.value`, true); |
| 139 | + } |
| 140 | + }, |
| 141 | + clearAll: function () { |
| 142 | + for (let i = 0; i < this.searchFilters.length; i++) { |
| 143 | + this.set(`searchFilters.${i}.value`, false); |
| 144 | + } |
| 145 | + }, |
| 146 | + viewMore: function () { |
| 147 | + this.set('viewLimit', 10); |
| 148 | + } |
| 149 | + }, |
| 150 | + getNumSourcesSearched() { |
| 151 | + let numSourcesToSearch = 0; |
| 152 | + for (let i = 0; i < this.searchFilters.length; i++) { |
| 153 | + if (this.searchFilters[i].value === true) { |
| 154 | + ++numSourcesToSearch; |
| 155 | + } |
| 156 | + } |
| 157 | + return numSourcesToSearch; |
| 158 | + } |
| 159 | +}); |
0 commit comments