mirror of https://github.com/Lissy93/dashy.git
⚡ Adds proxying support into Pi-Hole widgets (#391)
This commit is contained in:
parent
25fa6ebae8
commit
d2ff1438e2
|
@ -18,7 +18,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
// import axios from 'axios';
|
||||||
import WidgetMixin from '@/mixins/WidgetMixin';
|
import WidgetMixin from '@/mixins/WidgetMixin';
|
||||||
import ChartingMixin from '@/mixins/ChartingMixin';
|
import ChartingMixin from '@/mixins/ChartingMixin';
|
||||||
import { capitalize } from '@/utils/MiscHelpers';
|
import { capitalize } from '@/utils/MiscHelpers';
|
||||||
|
@ -55,15 +55,9 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
/* Make GET request to local pi-hole instance */
|
/* Make GET request to local pi-hole instance */
|
||||||
fetchData() {
|
fetchData() {
|
||||||
axios.get(this.endpoint)
|
this.makeRequest(this.endpoint)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.processData(response.data);
|
this.processData(response);
|
||||||
})
|
|
||||||
.catch((dataFetchError) => {
|
|
||||||
this.error('Unable to fetch data', dataFetchError);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.finishLoading();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/* Assign data variables to the returned data */
|
/* Assign data variables to the returned data */
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
|
||||||
import WidgetMixin from '@/mixins/WidgetMixin';
|
import WidgetMixin from '@/mixins/WidgetMixin';
|
||||||
import { showNumAsThousand } from '@/utils/MiscHelpers';
|
import { showNumAsThousand } from '@/utils/MiscHelpers';
|
||||||
|
|
||||||
|
@ -46,19 +45,13 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
/* Make GET request to local pi-hole instance */
|
/* Make GET request to local pi-hole instance */
|
||||||
fetchData() {
|
fetchData() {
|
||||||
axios.get(this.endpoint)
|
this.makeRequest(this.endpoint)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (Array.isArray(response.data)) {
|
if (Array.isArray(response)) {
|
||||||
this.error('Got success, but found no results, possible authorization error');
|
this.error('Got success, but found no results, possible authorization error');
|
||||||
} else {
|
} else {
|
||||||
this.processData(response.data);
|
this.processData(response);
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.catch((dataFetchError) => {
|
|
||||||
this.error('Unable to fetch data', dataFetchError);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.finishLoading();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/* Assign data variables to the returned data */
|
/* Assign data variables to the returned data */
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
|
||||||
import WidgetMixin from '@/mixins/WidgetMixin';
|
import WidgetMixin from '@/mixins/WidgetMixin';
|
||||||
import ChartingMixin from '@/mixins/ChartingMixin';
|
import ChartingMixin from '@/mixins/ChartingMixin';
|
||||||
|
|
||||||
|
@ -31,17 +30,23 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
/* Make GET request to local pi-hole instance */
|
/* Make GET request to local pi-hole instance */
|
||||||
fetchData() {
|
fetchData() {
|
||||||
axios.get(this.endpoint)
|
this.makeRequest(this.endpoint)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.processData(response.data);
|
if (this.validate(response)) {
|
||||||
})
|
this.processData(response);
|
||||||
.catch((dataFetchError) => {
|
}
|
||||||
this.error('Unable to fetch data', dataFetchError);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.finishLoading();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
validate(response) {
|
||||||
|
if (!response.ads_over_time || !response.domains_over_time) {
|
||||||
|
this.error('Expected data was not returned from Pi-Hole');
|
||||||
|
return false;
|
||||||
|
} else if (response.ads_over_time.length < 1) {
|
||||||
|
this.error('Request completed succesfully, but no data in Pi-Hole yet');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
/* Assign data variables to the returned data */
|
/* Assign data variables to the returned data */
|
||||||
processData(data) {
|
processData(data) {
|
||||||
const timeData = [];
|
const timeData = [];
|
||||||
|
|
Loading…
Reference in New Issue