Skip to content

Commit

Permalink
Merge pull request #1636 from OpenC3/date_time_widgets
Browse files Browse the repository at this point in the history
Add DATE and TIME widgets
  • Loading branch information
ryanmelt authored Oct 26, 2024
2 parents 3bacbe3 + 15b9db1 commit 3912e0c
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
SCREEN AUTO AUTO 0.5

VERTICAL
TITLE "<%= target_name %> Commanding Examples"
TITLE "<%= target_name %> Commanding Examples"

LABELVALUE <%= target_name %> HEALTH_STATUS COLLECTS
LABELVALUE <%= target_name %> HEALTH_STATUS COLLECT_TYPE
LABELVALUE <%= target_name %> HEALTH_STATUS DURATION
LABELVALUE <%= target_name %> HEALTH_STATUS COLLECTS
LABELVALUE <%= target_name %> HEALTH_STATUS COLLECT_TYPE
LABELVALUE <%= target_name %> HEALTH_STATUS DURATION

MATRIXBYCOLUMNS 2
VERTICALBOX "Send Collect Command:"
HORIZONTAL
LABEL "Type: "
Expand All @@ -32,11 +32,13 @@ VERTICAL
END

VERTICALBOX "Parameter-less Commands:"
NAMED_WIDGET GROUP RADIOGROUP 1 # Select 'Clear' initially, 0-based index
RADIOBUTTON 'Abort'
RADIOBUTTON 'Clear'
HORIZONTAL
NAMED_WIDGET GROUP RADIOGROUP 1 # Select 'Clear' initially, 0-based index
RADIOBUTTON 'Abort'
RADIOBUTTON 'Clear'
END
NAMED_WIDGET CHECK CHECKBUTTON 'Ignore Hazardous Checks' # No option is by default UNCHECKED
END
NAMED_WIDGET CHECK CHECKBUTTON 'Ignore Hazardous Checks' # No option is by default UNCHECKED
BUTTON 'Send' "screen.getNamedWidget('GROUP').selected() === 0 ? " +
"api.cmd('<%= target_name %> ABORT') : (screen.getNamedWidget('CHECK').checked() ? " +
"api.cmd_no_hazardous_check('<%= target_name %> CLEAR') : api.cmd('<%= target_name %> CLEAR'))"
Expand All @@ -54,4 +56,16 @@ VERTICAL
"var env = {}; env['TYPE'] = ctype;" \
"runScript('<%= target_name %>/procedures/'+script, !screen.getNamedWidget('BG').checked(), env)"
END

VERTICALBOX "Date / Time Chooser"
HORIZONTAL 5
NAMED_WIDGET DATE Date "Input Date"
NAMED_WIDGET TIME Time
END

BUTTON 'Alert' "var date=screen.getNamedWidget('DATE').text();" +
"var time=screen.getNamedWidget('TIME').text();" +
# You can have comments between string concatenations
"alert('DATE:'+date+' TIME:'+time)"
END
END
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
SCREEN AUTO AUTO 0.5

VERTICAL
TITLE "<%= target_name %> Commanding Examples"
TITLE "<%= target_name %> Commanding Examples"

LABELVALUE <%= target_name %> HEALTH_STATUS COLLECTS
LABELVALUE <%= target_name %> HEALTH_STATUS COLLECT_TYPE
LABELVALUE <%= target_name %> HEALTH_STATUS DURATION
LABELVALUE <%= target_name %> HEALTH_STATUS COLLECTS
LABELVALUE <%= target_name %> HEALTH_STATUS COLLECT_TYPE
LABELVALUE <%= target_name %> HEALTH_STATUS DURATION

MATRIXBYCOLUMNS 2
VERTICALBOX "Send Collect Command:"
HORIZONTAL
LABEL "Type: "
Expand All @@ -32,11 +32,13 @@ VERTICAL
END

VERTICALBOX "Parameter-less Commands:"
NAMED_WIDGET GROUP RADIOGROUP 1 # Select 'Clear' initially, 0-based index
RADIOBUTTON 'Abort'
RADIOBUTTON 'Clear'
HORIZONTAL
NAMED_WIDGET GROUP RADIOGROUP 1 # Select 'Clear' initially, 0-based index
RADIOBUTTON 'Abort'
RADIOBUTTON 'Clear'
END
NAMED_WIDGET CHECK CHECKBUTTON 'Ignore Hazardous Checks' # No option is by default UNCHECKED
END
NAMED_WIDGET CHECK CHECKBUTTON 'Ignore Hazardous Checks' # No option is by default UNCHECKED
BUTTON 'Send' "screen.getNamedWidget('GROUP').selected() === 0 ? " +
"api.cmd('<%= target_name %> ABORT') : (screen.getNamedWidget('CHECK').checked() ? " +
"api.cmd_no_hazardous_check('<%= target_name %> CLEAR') : api.cmd('<%= target_name %> CLEAR'))"
Expand All @@ -50,8 +52,20 @@ VERTICAL
BUTTON 'Run Script' "var script=screen.getNamedWidget('SCRIPTNAME').text();" \
"var ctype=screen.getNamedWidget('COLLECT_TYPE').text();" \
# Set some environment variables to be used by the script as ENV['TYPE']
# See INST2/procedures/checks.rb for an example of usage
# See INST2/procedures/checks.py for an example of usage
"var env = {}; env['TYPE'] = ctype;" \
"runScript('<%= target_name %>/procedures/'+script, !screen.getNamedWidget('BG').checked(), env)"
END

VERTICALBOX "Date / Time Chooser"
HORIZONTAL 5
NAMED_WIDGET DATE Date "Input Date"
NAMED_WIDGET TIME Time
END

BUTTON 'Alert' "var date=screen.getNamedWidget('DATE').text();" +
"var time=screen.getNamedWidget('TIME').text();" +
# You can have comments between string concatenations
"alert('DATE:'+date+' TIME:'+time)"
END
END
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!--
# Copyright 2024 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.
-->

<template>
<v-text-field
v-model="dateValue"
:label="label"
:style="computedStyle"
type="date"
hide-details
/>
</template>

<script>
import Widget from './Widget'
import TimeFilters from '@openc3/tool-common/src/tools/base/util/timeFilters.js'

export default {
mixins: [Widget, TimeFilters],
data() {
return {
label: 'Date',
dateValue: '',
}
},
created() {
// Look through the settings and see if we're a NAMED_WIDGET
this.settings.forEach((setting) => {
if (setting[0] === 'NAMED_WIDGET') {
setting[2].setNamedWidget(setting[1], this)
}
})
if (this.parameters[0]) {
this.label = this.parameters[0]
}
this.dateValue = this.formatDate(new Date(), this.screen.timeZone)
},
methods: {
text() {
return this.dateValue
},
date() {
return this.dateValue
},
},
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!--
# Copyright 2024 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.
-->

<template>
<v-text-field
v-model="timeValue"
:label="label"
:style="computedStyle"
type="time"
hide-details
/>
</template>

<script>
import Widget from './Widget'
import TimeFilters from '@openc3/tool-common/src/tools/base/util/timeFilters.js'

export default {
mixins: [Widget, TimeFilters],
data() {
return {
label: 'Time',
timeValue: '',
}
},
created() {
// Look through the settings and see if we're a NAMED_WIDGET
this.settings.forEach((setting) => {
if (setting[0] === 'NAMED_WIDGET') {
setting[2].setNamedWidget(setting[1], this)
}
})
if (this.parameters[0]) {
this.label = this.parameters[0]
}
this.timeValue = this.formatTime(new Date(), this.screen.timeZone)
},
methods: {
text() {
return this.timeValue
},
time() {
return this.timeValue
},
},
}
</script>
28 changes: 28 additions & 0 deletions openc3/data/config/widgets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,20 @@ Interactive Widgets:
BUTTON 'Start Collect' 'var type = screen.getNamedWidget("COLLECT_TYPE").text();' +
'api.cmd("INST COLLECT with TYPE "+type+", DURATION 10.0")'
NAMED_WIDGET COLLECT_TYPE COMBOBOX NORMAL SPECIAL
DATE:
summary: Displays a date picker
description:
Note this is of limited use by itself and is primarily used in
conjunction with NAMED_WIDGET.
parameters:
- name: Date label
required: false
description: Text to label the data selection ('Date' by default)
values: .+
example: |
BUTTON 'Alert Date' 'var date = screen.getNamedWidget("DATE").text();' +
'alert("Date:"+date)'
NAMED_WIDGET DATE DATE
RADIOGROUP:
summary: Creates a group of RADIOBUTTONs
description: RADIOBUTTONs must be part of a group to enable selection logic
Expand Down Expand Up @@ -1464,6 +1478,20 @@ Interactive Widgets:
NAMED_WIDGET DURATION TEXTFIELD 12 "10.0"
BUTTON 'Start Collect' 'var dur = screen.getNamedWidget("DURATION").text();' +
'api.cmd("INST COLLECT with TYPE NORMAL, DURATION "+dur+"")'
TIME:
summary: Displays a time picker
description:
Note this is of limited use by itself and is primarily used in
conjunction with NAMED_WIDGET.
parameters:
- name: Time label
required: false
description: Text to label the time selection ('Time' by default)
values: .+
example: |
BUTTON 'Alert Time' 'var time = screen.getNamedWidget("TIME").text();' +
'alert("Time:"+time)'
NAMED_WIDGET TIME TIME
Canvas Widgets:
description:
Canvas Widgets are used to draw custom displays into telemetry screens.
Expand Down

0 comments on commit 3912e0c

Please sign in to comment.