Skip to content

Commit 706f74a

Browse files
committed
feat: add sorting functionality for tags and info columns in streams table
1 parent a9f59e5 commit 706f74a

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/components/pages/StreamsPage.vue

+22-19
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,18 @@
2121
{{ sortOrder === 1 ? "▲" : "▼" }}
2222
</span>
2323
</th>
24-
<th>Tags</th>
25-
<th>Info</th>
24+
<th @click="setSort('tags')" style="cursor: pointer">
25+
Tags
26+
<span v-if="sortKey === 'tags'">
27+
{{ sortOrder === 1 ? "▲" : "▼" }}
28+
</span>
29+
</th>
30+
<th @click="setSort('info')" style="cursor: pointer">
31+
Info
32+
<span v-if="sortKey === 'info'">
33+
{{ sortOrder === 1 ? "▲" : "▼" }}
34+
</span>
35+
</th>
2636
<th @click="setSort('address')" style="cursor: pointer">
2737
Device Address
2838
<span v-if="sortKey === 'address'">
@@ -116,7 +126,6 @@
116126

117127
<script>
118128
import {
119-
// Importing application-wide functions and reactive variables for stream management.
120129
searchStreams,
121130
streams,
122131
streamCount,
@@ -133,52 +142,48 @@ import { ref, computed } from "vue";
133142
export default {
134143
name: "StreamsPage",
135144
setup() {
136-
// Reactive variables for sorting streams.
137-
const sortKey = ref("name"); // Default sort by "name"
138-
const sortOrder = ref(1); // 1 for ascending order, -1 for descending order
145+
const sortKey = ref("name");
146+
const sortOrder = ref(1);
139147
140-
// Function to toggle or set the sorting key and order.
141148
function setSort(key) {
142149
if (sortKey.value === key) {
143-
// If the same key is clicked again, reverse the sorting order.
144150
sortOrder.value = -sortOrder.value;
145151
} else {
146-
// If a different key is clicked, change sort key and reset order to ascending.
147152
sortKey.value = key;
148153
sortOrder.value = 1;
149154
}
150155
}
151156
152-
// Helper function to retrieve the value for sorting based on the key.
153157
function getSortValue(stream, key) {
154158
switch (key) {
155159
case "name":
156-
// Returns the stream name for sorting.
157160
return stream.name;
158161
case "mcast":
159-
// Returns the multicast address for sorting.
160162
return stream.mcast;
161163
case "address":
162-
// Returns the device address from the stream's origin.
163164
return stream.origin.address;
164165
case "format":
165-
// Returns a formatted string only if the stream is supported.
166166
return stream.isSupported
167167
? `${stream.codec} ${stream.samplerate}Hz ${stream.channels}`
168168
: "";
169+
case "info":
170+
return stream.media[0].description ? stream.media[0].description : "";
171+
case "tags":
172+
var tags = "";
173+
if (stream.dante) tags += "Dante ";
174+
if (stream.manual) tags += "Manual ";
175+
if (stream.announce) tags += "SAP ";
176+
return tags.trim();
169177
default:
170-
// Returns generic property based on the key.
171178
return stream[key];
172179
}
173180
}
174181
175-
// Computed property that returns a sorted list of streams based on the selected sort key and order.
176182
const sortedStreams = computed(() => {
177183
const streamsList = searchStreams();
178184
return streamsList.slice().sort((a, b) => {
179185
let propA = getSortValue(a, sortKey.value);
180186
let propB = getSortValue(b, sortKey.value);
181-
// For string values, perform case-insensitive comparison.
182187
if (typeof propA === "string") propA = propA.toLowerCase();
183188
if (typeof propB === "string") propB = propB.toLowerCase();
184189
if (propA < propB) return -1 * sortOrder.value;
@@ -187,7 +192,6 @@ export default {
187192
});
188193
});
189194
190-
// Expose methods and reactive variables to the template.
191195
return {
192196
sortedStreams,
193197
setSort,
@@ -206,7 +210,6 @@ export default {
206210
};
207211
},
208212
methods: {
209-
// Method to delete a manual stream by sending a message through the electronAPI.
210213
deleteStream(id) {
211214
window.electronAPI.sendMessage({ type: "delete", data: id });
212215
},

0 commit comments

Comments
 (0)