Skip to content

Commit

Permalink
Still don't love the web UI view
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Aug 23, 2023
1 parent 2b52cb0 commit ce157e1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
28 changes: 17 additions & 11 deletions photon-client/src/components/settings/NetworkingCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const isValidHostname = (v: string | undefined) => {
return hostnameRegex.test(v);
};
function allowNetworkChanges() {
return useSettingsStore().network.shouldManage && useSettingsStore().network.canManage;
};
const saveGeneralSettings = () => {
const changingStaticIp =
useSettingsStore().network.connectionType === NetworkConnectionType.Static;
Expand Down Expand Up @@ -142,43 +146,45 @@ const netManagerIfaceIdx = computed<number>({
The NetworkTables Server Address is not set or is invalid.
NetworkTables is unable to connect.
</v-banner>
<cv-select
v-model="netManagerIfaceIdx"
label="NetworkManager interface"
:select-cols="12-4"
tooltip="hello"
:items="ifaceNames()"
/>
<cv-radio
v-model="useSettingsStore().network.connectionType"
label="IP Assignment Mode"
tooltip="DHCP will make the radio (router) automatically assign an IP address; this may result in an IP address that changes across reboots. Static IP assignment means that you pick the IP address and it won't change."
:input-cols="12 - 4"
:list="['DHCP', 'Static']"
:disabled="!useSettingsStore().network.shouldManage"
:disabled="!allowNetworkChanges()"
/>
<cv-input
v-model="useSettingsStore().network.staticIp"
:input-cols="12 - 4"
label="Static IP"
:rules="[(v) => isValidIPv4(v) || 'Invalid IPv4 address']"
:disabled="useSettingsStore().network.connectionType !== NetworkConnectionType.Static || !useSettingsStore().network.shouldManage"
:disabled="!allowNetworkChanges()"
/>
<cv-input
v-model="useSettingsStore().network.hostname"
label="Hostname"
:input-cols="12-4"
:rules="[(v) => isValidHostname(v) || 'Invalid hostname']"
:disabled="!useSettingsStore().network.shouldManage"
:disabled="!allowNetworkChanges()"
/>
<v-divider/>
<span>Advanced Networking</span>
<cv-switch
v-model="useSettingsStore().network.shouldManage"
:disabled="!useSettingsStore().network.canManage"
label="Manage Device Networking"
tooltip="If enabled, Photon will manage device hostname and network settings."
class="mt-3 mb-3"
:label-cols="3"
:label-cols="4"
/>
<cv-select
v-model="netManagerIfaceIdx"
label="NetworkManager interface"
:disabled="!allowNetworkChanges()"
:select-cols="12-4"
tooltip="hello"
:items="ifaceNames()"
/>
<cv-switch
v-model="useSettingsStore().network.runNTServer"
Expand Down
1 change: 1 addition & 0 deletions photon-client/src/stores/settings/GeneralSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const useSettingsStore = defineStore("settings", {
network: {
ntServerAddress: "",
shouldManage: true,
canManage: true,
connectionType: NetworkConnectionType.DHCP,
staticIp: "",
hostname: "photonvision",
Expand Down
1 change: 1 addition & 0 deletions photon-client/src/types/SettingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface NetworkSettings {
hostname: string,
runNTServer: boolean
shouldManage: boolean,
canManage: boolean,
networkManagerIface?: string,
setStaticCommand?: string,
setDHCPcommand?: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public NetworkConfig(

public Map<String, Object> toHashMap() {
try {
return new ObjectMapper().convertValue(this, JacksonUtils.UIMap.class);
var ret = new ObjectMapper().convertValue(this, JacksonUtils.UIMap.class);
ret.put("canManage", this.deviceCanManageNetwork());
return ret;
} catch (Exception e) {
e.printStackTrace();
return new HashMap<>();
Expand All @@ -110,6 +112,7 @@ public void setShouldManage(boolean shouldManage) {
this.shouldManage = shouldManage && this.deviceCanManageNetwork();
}

@JsonIgnore
private boolean deviceCanManageNetwork() {
return Platform.isLinux();
}
Expand Down

0 comments on commit ce157e1

Please sign in to comment.