Skip to content

Commit

Permalink
Move sensors to use sensor collection schema (#7)
Browse files Browse the repository at this point in the history
Before to get all the Sensors 3 of a chassis,
3 calls were made:
/redfish/v1/Chassis/{chassis}/Power
/redfish/v1/Chassis/{chassis}/Thermal
/redfish/v1/Chassis/{chassis}/Sensors

With this change:
https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/40169
All that is needed is a call to /redfish/v1/Chassis/{chassis}/Sensors

Note: The threshold property is optional on some sensors,
Optional chaining operator (?.) is used to return undefined
if a property does not exist.

Signed-off-by: Dixsie Wolmers <[email protected]>
  • Loading branch information
dixsie authored and rfrandse committed Jan 28, 2022
1 parent d02d3ff commit 4fa3190
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 16 deletions.
21 changes: 9 additions & 12 deletions src/store/modules/HardwareStatus/SensorsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,22 @@ const SensorsStore = {
},
},
actions: {
async getAllSensors({ dispatch }) {
const collection = await dispatch('getChassisCollection');
if (!collection) return;
const promises = collection.reduce((acc, id) => {
acc.push(dispatch('getSensors', id));
acc.push(dispatch('getThermalSensors', id));
acc.push(dispatch('getPowerSensors', id));
return acc;
}, []);
return await api.all(promises);
},
async getChassisCollection() {
return await api
.get('/redfish/v1/Chassis')
.get('/redfish/v1/')
.then((response) => api.get(response.data.Chassis['@odata.id']))
.then(({ data: { Members } }) =>
Members.map((member) => member['@odata.id'])
)
.catch((error) => console.log(error));
},
async getAllSensors({ dispatch }) {
const collection = await dispatch('getChassisCollection');
if (!collection) return;
return await api
.all(collection.map((chassis) => dispatch('getSensors', chassis)))
.catch((error) => console.log(error));
},
async getSensors({ commit }, id) {
const sensors = await api
.get(`${id}/Sensors`)
Expand Down
51 changes: 47 additions & 4 deletions src/views/HardwareStatus/Sensors/Sensors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
show-empty
:no-border-collapse="true"
:items="filteredSensors"
:busy="isBusy"
:fields="fields"
:per-page="perPage"
:current-page="currentPage"
:sort-desc="true"
:sort-compare="sortCompare"
:filter="searchFilter"
Expand Down Expand Up @@ -96,6 +99,32 @@
</b-table>
</b-col>
</b-row>
<!-- Table pagination -->
<b-row>
<b-col sm="6">
<b-form-group
class="table-pagination-select"
:label="$t('global.table.itemsPerPage')"
label-for="pagination-items-per-page"
>
<b-form-select
id="pagination-items-per-page"
v-model="perPage"
:options="itemsPerPageOptions"
/>
</b-form-group>
</b-col>
<b-col sm="6">
<b-pagination
v-model="currentPage"
first-number
last-number
:per-page="perPage"
:total-rows="getTotalRowCount(filteredRows)"
aria-controls="table-sensors"
/>
</b-col>
</b-row>
</b-container>
</template>

Expand All @@ -107,7 +136,11 @@ import TableFilter from '@/components/Global/TableFilter';
import TableToolbar from '@/components/Global/TableToolbar';
import TableToolbarExport from '@/components/Global/TableToolbarExport';
import TableCellCount from '@/components/Global/TableCellCount';
import BVPaginationMixin, {
currentPage,
perPage,
itemsPerPageOptions,
} from '@/components/Mixins/BVPaginationMixin';
import BVTableSelectableMixin, {
selectedRows,
tableHeaderCheckboxModel,
Expand All @@ -120,7 +153,6 @@ import TableSortMixin from '@/components/Mixins/TableSortMixin';
import SearchFilterMixin, {
searchFilter,
} from '@/components/Mixins/SearchFilterMixin';
export default {
name: 'Sensors',
components: {
Expand All @@ -133,6 +165,7 @@ export default {
TableToolbarExport,
},
mixins: [
BVPaginationMixin,
TableFilterMixin,
BVTableSelectableMixin,
LoadingBarMixin,
Expand Down Expand Up @@ -173,7 +206,6 @@ export default {
formatter: this.dataFormatter,
label: this.$t('pageSensors.table.lowerWarning'),
},
{
key: 'currentValue',
formatter: this.dataFormatter,
Expand All @@ -198,6 +230,10 @@ export default {
},
],
activeFilters: [],
currentPage: currentPage,
itemsPerPageOptions: itemsPerPageOptions,
isBusy: false,
perPage: perPage,
searchFilter: searchFilter,
searchTotalFilteredRows: 0,
selectedRows: selectedRows,
Expand All @@ -222,9 +258,16 @@ export default {
this.startLoader();
this.$store
.dispatch('sensors/getAllSensors')
.finally(() => this.endLoader());
.then(this.toggleBusy())
.finally(() => {
this.endLoader();
this.toggleBusy();
});
},
methods: {
toggleBusy() {
this.isBusy = !this.isBusy;
},
sortCompare(a, b, key) {
if (key === 'status') {
return this.sortStatus(a, b, key);
Expand Down

0 comments on commit 4fa3190

Please sign in to comment.