Committed by
Gerrit Code Review
ONOS-2876 -- GUI - Setting friendly device names.
Change-Id: I3e84f473af4c26c9a5e8b5cf9598d1448c4be20c
Showing
5 changed files
with
109 additions
and
93 deletions
| ... | @@ -33,6 +33,8 @@ import org.onosproject.ui.RequestHandler; | ... | @@ -33,6 +33,8 @@ import org.onosproject.ui.RequestHandler; |
| 33 | import org.onosproject.ui.UiMessageHandler; | 33 | import org.onosproject.ui.UiMessageHandler; |
| 34 | import org.onosproject.ui.table.TableModel; | 34 | import org.onosproject.ui.table.TableModel; |
| 35 | import org.onosproject.ui.table.TableRequestHandler; | 35 | import org.onosproject.ui.table.TableRequestHandler; |
| 36 | +import org.slf4j.Logger; | ||
| 37 | +import org.slf4j.LoggerFactory; | ||
| 36 | 38 | ||
| 37 | import java.util.ArrayList; | 39 | import java.util.ArrayList; |
| 38 | import java.util.Collection; | 40 | import java.util.Collection; |
| ... | @@ -61,6 +63,8 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -61,6 +63,8 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 61 | private static final String DEV_NAME_CHANGE_REQ = "deviceNameChangeRequest"; | 63 | private static final String DEV_NAME_CHANGE_REQ = "deviceNameChangeRequest"; |
| 62 | private static final String DEV_NAME_CHANGE_RESP = "deviceNameChangeResponse"; | 64 | private static final String DEV_NAME_CHANGE_RESP = "deviceNameChangeResponse"; |
| 63 | 65 | ||
| 66 | + private static final String ZERO_URI = "of:0000000000000000"; | ||
| 67 | + | ||
| 64 | private static final String ID = "id"; | 68 | private static final String ID = "id"; |
| 65 | private static final String TYPE = "type"; | 69 | private static final String TYPE = "type"; |
| 66 | private static final String AVAILABLE = "available"; | 70 | private static final String AVAILABLE = "available"; |
| ... | @@ -80,17 +84,21 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -80,17 +84,21 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 80 | private static final String ENABLED = "enabled"; | 84 | private static final String ENABLED = "enabled"; |
| 81 | private static final String SPEED = "speed"; | 85 | private static final String SPEED = "speed"; |
| 82 | private static final String NAME = "name"; | 86 | private static final String NAME = "name"; |
| 87 | + private static final String WARN = "warn"; | ||
| 83 | 88 | ||
| 84 | 89 | ||
| 85 | private static final String[] COL_IDS = { | 90 | private static final String[] COL_IDS = { |
| 86 | - AVAILABLE, AVAILABLE_IID, TYPE_IID, ID, | 91 | + AVAILABLE, AVAILABLE_IID, TYPE_IID, |
| 87 | - NUM_PORTS, MASTER_ID, MFR, HW, SW, | 92 | + NAME, ID, MASTER_ID, NUM_PORTS, MFR, HW, SW, |
| 88 | PROTOCOL, CHASSIS_ID, SERIAL | 93 | PROTOCOL, CHASSIS_ID, SERIAL |
| 89 | }; | 94 | }; |
| 90 | 95 | ||
| 91 | private static final String ICON_ID_ONLINE = "active"; | 96 | private static final String ICON_ID_ONLINE = "active"; |
| 92 | private static final String ICON_ID_OFFLINE = "inactive"; | 97 | private static final String ICON_ID_OFFLINE = "inactive"; |
| 93 | 98 | ||
| 99 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
| 100 | + | ||
| 101 | + | ||
| 94 | @Override | 102 | @Override |
| 95 | protected Collection<RequestHandler> createRequestHandlers() { | 103 | protected Collection<RequestHandler> createRequestHandlers() { |
| 96 | return ImmutableSet.of( | 104 | return ImmutableSet.of( |
| ... | @@ -100,6 +108,17 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -100,6 +108,17 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 100 | ); | 108 | ); |
| 101 | } | 109 | } |
| 102 | 110 | ||
| 111 | + // Get friendly name of the device from the annotations | ||
| 112 | + private static String deviceName(Device device) { | ||
| 113 | + String name = device.annotations().value(AnnotationKeys.NAME); | ||
| 114 | + return isNullOrEmpty(name) ? device.id().toString() : name; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + private static String deviceProtocol(Device device) { | ||
| 118 | + String protocol = device.annotations().value(PROTOCOL); | ||
| 119 | + return protocol != null ? protocol : ""; | ||
| 120 | + } | ||
| 121 | + | ||
| 103 | private static String getTypeIconId(Device d) { | 122 | private static String getTypeIconId(Device d) { |
| 104 | return DEV_ICON_PREFIX + d.type().toString(); | 123 | return DEV_ICON_PREFIX + d.type().toString(); |
| 105 | } | 124 | } |
| ... | @@ -130,16 +149,15 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -130,16 +149,15 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 130 | boolean available = ds.isAvailable(id); | 149 | boolean available = ds.isAvailable(id); |
| 131 | String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE; | 150 | String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE; |
| 132 | 151 | ||
| 133 | - String protocol = dev.annotations().value(PROTOCOL); | ||
| 134 | - | ||
| 135 | row.cell(ID, id) | 152 | row.cell(ID, id) |
| 153 | + .cell(NAME, deviceName(dev)) | ||
| 136 | .cell(AVAILABLE, available) | 154 | .cell(AVAILABLE, available) |
| 137 | .cell(AVAILABLE_IID, iconId) | 155 | .cell(AVAILABLE_IID, iconId) |
| 138 | .cell(TYPE_IID, getTypeIconId(dev)) | 156 | .cell(TYPE_IID, getTypeIconId(dev)) |
| 139 | .cell(MFR, dev.manufacturer()) | 157 | .cell(MFR, dev.manufacturer()) |
| 140 | .cell(HW, dev.hwVersion()) | 158 | .cell(HW, dev.hwVersion()) |
| 141 | .cell(SW, dev.swVersion()) | 159 | .cell(SW, dev.swVersion()) |
| 142 | - .cell(PROTOCOL, protocol != null ? protocol : "") | 160 | + .cell(PROTOCOL, deviceProtocol(dev)) |
| 143 | .cell(NUM_PORTS, ds.getPorts(id).size()) | 161 | .cell(NUM_PORTS, ds.getPorts(id).size()) |
| 144 | .cell(MASTER_ID, ms.getMasterFor(id)); | 162 | .cell(MASTER_ID, ms.getMasterFor(id)); |
| 145 | } | 163 | } |
| ... | @@ -153,20 +171,16 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -153,20 +171,16 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 153 | 171 | ||
| 154 | @Override | 172 | @Override |
| 155 | public void process(long sid, ObjectNode payload) { | 173 | public void process(long sid, ObjectNode payload) { |
| 156 | - String id = string(payload, "id", "of:0000000000000000"); | 174 | + String id = string(payload, ID, ZERO_URI); |
| 157 | 175 | ||
| 158 | DeviceId deviceId = deviceId(id); | 176 | DeviceId deviceId = deviceId(id); |
| 159 | DeviceService service = get(DeviceService.class); | 177 | DeviceService service = get(DeviceService.class); |
| 160 | MastershipService ms = get(MastershipService.class); | 178 | MastershipService ms = get(MastershipService.class); |
| 161 | Device device = service.getDevice(deviceId); | 179 | Device device = service.getDevice(deviceId); |
| 162 | - ObjectNode data = MAPPER.createObjectNode(); | 180 | + ObjectNode data = objectNode(); |
| 163 | 181 | ||
| 164 | data.put(ID, deviceId.toString()); | 182 | data.put(ID, deviceId.toString()); |
| 165 | - | 183 | + data.put(NAME, deviceName(device)); |
| 166 | - // Get friendly name of the device from the annotations | ||
| 167 | - String name = device.annotations().value(AnnotationKeys.NAME); | ||
| 168 | - data.put(NAME, isNullOrEmpty(name) ? deviceId.toString() : name); | ||
| 169 | - | ||
| 170 | data.put(TYPE, capitalizeFully(device.type().toString())); | 184 | data.put(TYPE, capitalizeFully(device.type().toString())); |
| 171 | data.put(TYPE_IID, getTypeIconId(device)); | 185 | data.put(TYPE_IID, getTypeIconId(device)); |
| 172 | data.put(MFR, device.manufacturer()); | 186 | data.put(MFR, device.manufacturer()); |
| ... | @@ -175,9 +189,9 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -175,9 +189,9 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 175 | data.put(SERIAL, device.serialNumber()); | 189 | data.put(SERIAL, device.serialNumber()); |
| 176 | data.put(CHASSIS_ID, device.chassisId().toString()); | 190 | data.put(CHASSIS_ID, device.chassisId().toString()); |
| 177 | data.put(MASTER_ID, ms.getMasterFor(deviceId).toString()); | 191 | data.put(MASTER_ID, ms.getMasterFor(deviceId).toString()); |
| 178 | - data.put(PROTOCOL, device.annotations().value(PROTOCOL)); | 192 | + data.put(PROTOCOL, deviceProtocol(device)); |
| 179 | 193 | ||
| 180 | - ArrayNode ports = MAPPER.createArrayNode(); | 194 | + ArrayNode ports = arrayNode(); |
| 181 | 195 | ||
| 182 | List<Port> portList = new ArrayList<>(service.getPorts(deviceId)); | 196 | List<Port> portList = new ArrayList<>(service.getPorts(deviceId)); |
| 183 | Collections.sort(portList, (p1, p2) -> { | 197 | Collections.sort(portList, (p1, p2) -> { |
| ... | @@ -190,13 +204,13 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -190,13 +204,13 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 190 | } | 204 | } |
| 191 | data.set(PORTS, ports); | 205 | data.set(PORTS, ports); |
| 192 | 206 | ||
| 193 | - ObjectNode rootNode = MAPPER.createObjectNode(); | 207 | + ObjectNode rootNode = objectNode(); |
| 194 | rootNode.set(DETAILS, data); | 208 | rootNode.set(DETAILS, data); |
| 195 | sendMessage(DEV_DETAILS_RESP, 0, rootNode); | 209 | sendMessage(DEV_DETAILS_RESP, 0, rootNode); |
| 196 | } | 210 | } |
| 197 | 211 | ||
| 198 | private ObjectNode portData(Port p, DeviceId id) { | 212 | private ObjectNode portData(Port p, DeviceId id) { |
| 199 | - ObjectNode port = MAPPER.createObjectNode(); | 213 | + ObjectNode port = objectNode(); |
| 200 | LinkService ls = get(LinkService.class); | 214 | LinkService ls = get(LinkService.class); |
| 201 | String name = p.annotations().value(AnnotationKeys.PORT_NAME); | 215 | String name = p.annotations().value(AnnotationKeys.PORT_NAME); |
| 202 | 216 | ||
| ... | @@ -221,6 +235,7 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -221,6 +235,7 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 221 | } | 235 | } |
| 222 | } | 236 | } |
| 223 | 237 | ||
| 238 | + | ||
| 224 | // handler for changing device friendly name | 239 | // handler for changing device friendly name |
| 225 | private final class NameChangeHandler extends RequestHandler { | 240 | private final class NameChangeHandler extends RequestHandler { |
| 226 | private NameChangeHandler() { | 241 | private NameChangeHandler() { |
| ... | @@ -229,13 +244,17 @@ public class DeviceViewMessageHandler extends UiMessageHandler { | ... | @@ -229,13 +244,17 @@ public class DeviceViewMessageHandler extends UiMessageHandler { |
| 229 | 244 | ||
| 230 | @Override | 245 | @Override |
| 231 | public void process(long sid, ObjectNode payload) { | 246 | public void process(long sid, ObjectNode payload) { |
| 232 | - DeviceId deviceId = deviceId(string(payload, "id", "of:0000000000000000")); | 247 | + DeviceId deviceId = deviceId(string(payload, ID, ZERO_URI)); |
| 248 | + String name = emptyToNull(string(payload, NAME, null)); | ||
| 249 | + log.debug("Name change request: {} -- '{}'", deviceId, name); | ||
| 250 | + | ||
| 233 | NetworkConfigService service = get(NetworkConfigService.class); | 251 | NetworkConfigService service = get(NetworkConfigService.class); |
| 234 | - BasicDeviceConfig cfg = service.getConfig(deviceId, BasicDeviceConfig.class); | 252 | + BasicDeviceConfig cfg = |
| 253 | + service.addConfig(deviceId, BasicDeviceConfig.class); | ||
| 235 | 254 | ||
| 236 | - // Name attribute missing (or being empty) from the payload means | 255 | + // Name attribute missing from the payload (or empty string) |
| 237 | - // that the friendly name should be unset. | 256 | + // means that the friendly name should be unset. |
| 238 | - cfg.name(emptyToNull(string(payload, "name", null))); | 257 | + cfg.name(name); |
| 239 | cfg.apply(); | 258 | cfg.apply(); |
| 240 | sendMessage(DEV_NAME_CHANGE_RESP, 0, payload); | 259 | sendMessage(DEV_NAME_CHANGE_RESP, 0, payload); |
| 241 | } | 260 | } | ... | ... |
| ... | @@ -25,6 +25,7 @@ | ... | @@ -25,6 +25,7 @@ |
| 25 | 25 | ||
| 26 | // internal state | 26 | // internal state |
| 27 | var enabled = true, | 27 | var enabled = true, |
| 28 | + globalEnabled = true, | ||
| 28 | keyHandler = { | 29 | keyHandler = { |
| 29 | globalKeys: {}, | 30 | globalKeys: {}, |
| 30 | maskedKeys: {}, | 31 | maskedKeys: {}, |
| ... | @@ -116,6 +117,9 @@ | ... | @@ -116,6 +117,9 @@ |
| 116 | } | 117 | } |
| 117 | 118 | ||
| 118 | function quickHelp(view, key, code, ev) { | 119 | function quickHelp(view, key, code, ev) { |
| 120 | + if (!globalEnabled) { | ||
| 121 | + return false; | ||
| 122 | + } | ||
| 119 | qhs.showQuickHelp(keyHandler); | 123 | qhs.showQuickHelp(keyHandler); |
| 120 | return true; | 124 | return true; |
| 121 | } | 125 | } |
| ... | @@ -126,6 +130,9 @@ | ... | @@ -126,6 +130,9 @@ |
| 126 | } | 130 | } |
| 127 | 131 | ||
| 128 | function toggleTheme(view, key, code, ev) { | 132 | function toggleTheme(view, key, code, ev) { |
| 133 | + if (!globalEnabled) { | ||
| 134 | + return false; | ||
| 135 | + } | ||
| 129 | ts.toggleTheme(); | 136 | ts.toggleTheme(); |
| 130 | return true; | 137 | return true; |
| 131 | } | 138 | } |
| ... | @@ -226,6 +233,9 @@ | ... | @@ -226,6 +233,9 @@ |
| 226 | enableKeys: function (b) { | 233 | enableKeys: function (b) { |
| 227 | enabled = b; | 234 | enabled = b; |
| 228 | }, | 235 | }, |
| 236 | + enableGlobalKeys: function (b) { | ||
| 237 | + globalEnabled = b; | ||
| 238 | + }, | ||
| 229 | checkNotGlobal: checkNotGlobal | 239 | checkNotGlobal: checkNotGlobal |
| 230 | }; | 240 | }; |
| 231 | }]); | 241 | }]); | ... | ... |
| ... | @@ -75,30 +75,15 @@ | ... | @@ -75,30 +75,15 @@ |
| 75 | margin: 8px 0; | 75 | margin: 8px 0; |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | -#device-details-panel .name-div { | ||
| 79 | - height: 20px; | ||
| 80 | - padding: 8px 0 0 8px; | ||
| 81 | -} | ||
| 82 | - | ||
| 83 | -#device-details-panel .name-div span { | ||
| 84 | - display: inline-block; | ||
| 85 | -} | ||
| 86 | - | ||
| 87 | -#device-details-panel .name-div .label { | ||
| 88 | - font-style: italic; | ||
| 89 | - padding-right: 12px; | ||
| 90 | - /* works for both light and dark themes ... */ | ||
| 91 | - color: #777; | ||
| 92 | -} | ||
| 93 | - | ||
| 94 | -#device-details-panel .name-div .value { | ||
| 95 | -} | ||
| 96 | - | ||
| 97 | #device-details-panel .editable { | 78 | #device-details-panel .editable { |
| 98 | cursor: pointer; | 79 | cursor: pointer; |
| 99 | border-bottom: 1px dashed darkgreen; | 80 | border-bottom: 1px dashed darkgreen; |
| 100 | } | 81 | } |
| 101 | 82 | ||
| 83 | +#device-details-panel h2 input { | ||
| 84 | + font-size: 1.0em; | ||
| 85 | +} | ||
| 86 | + | ||
| 102 | #device-details-panel .top div.left { | 87 | #device-details-panel .top div.left { |
| 103 | float: left; | 88 | float: left; |
| 104 | padding: 0 18px 0 0; | 89 | padding: 0 18px 0 0; | ... | ... |
| ... | @@ -35,13 +35,14 @@ | ... | @@ -35,13 +35,14 @@ |
| 35 | <tr> | 35 | <tr> |
| 36 | <td colId="available" class="table-icon" sortable></td> | 36 | <td colId="available" class="table-icon" sortable></td> |
| 37 | <td colId="type" class="table-icon" sortable></td> | 37 | <td colId="type" class="table-icon" sortable></td> |
| 38 | + <td colId="name" sortable>Friendly Name </td> | ||
| 38 | <td colId="id" sortable>Device ID </td> | 39 | <td colId="id" sortable>Device ID </td> |
| 39 | <td colId="masterid" sortable>Master Instance </td> | 40 | <td colId="masterid" sortable>Master Instance </td> |
| 40 | - <td colId="num_ports" sortable>Ports </td> | 41 | + <td colId="num_ports" col-width="60px" sortable>Ports </td> |
| 41 | <td colId="mfr" sortable>Vendor </td> | 42 | <td colId="mfr" sortable>Vendor </td> |
| 42 | <td colId="hw" sortable>H/W Version </td> | 43 | <td colId="hw" sortable>H/W Version </td> |
| 43 | <td colId="sw" sortable>S/W Version </td> | 44 | <td colId="sw" sortable>S/W Version </td> |
| 44 | - <td colId="protocol" sortable>Protocol </td> | 45 | + <td colId="protocol" col-width="80px" sortable>Protocol </td> |
| 45 | </tr> | 46 | </tr> |
| 46 | </table> | 47 | </table> |
| 47 | </div> | 48 | </div> |
| ... | @@ -64,6 +65,7 @@ | ... | @@ -64,6 +65,7 @@ |
| 64 | <td class="table-icon"> | 65 | <td class="table-icon"> |
| 65 | <div icon icon-id="{{dev._iconid_type}}"></div> | 66 | <div icon icon-id="{{dev._iconid_type}}"></div> |
| 66 | </td> | 67 | </td> |
| 68 | + <td>{{dev.name}}</td> | ||
| 67 | <td>{{dev.id}}</td> | 69 | <td>{{dev.id}}</td> |
| 68 | <td>{{dev.masterid}}</td> | 70 | <td>{{dev.masterid}}</td> |
| 69 | <td>{{dev.num_ports}}</td> | 71 | <td>{{dev.num_ports}}</td> | ... | ... |
| ... | @@ -22,7 +22,7 @@ | ... | @@ -22,7 +22,7 @@ |
| 22 | 'use strict'; | 22 | 'use strict'; |
| 23 | 23 | ||
| 24 | // injected refs | 24 | // injected refs |
| 25 | - var $log, $scope, $location, fs, mast, ps, wss, is, ns; | 25 | + var $log, $scope, $loc, fs, mast, ps, wss, is, ns, ks; |
| 26 | 26 | ||
| 27 | // internal state | 27 | // internal state |
| 28 | var detailsPanel, | 28 | var detailsPanel, |
| ... | @@ -43,13 +43,15 @@ | ... | @@ -43,13 +43,15 @@ |
| 43 | pName = 'device-details-panel', | 43 | pName = 'device-details-panel', |
| 44 | detailsReq = 'deviceDetailsRequest', | 44 | detailsReq = 'deviceDetailsRequest', |
| 45 | detailsResp = 'deviceDetailsResponse', | 45 | detailsResp = 'deviceDetailsResponse', |
| 46 | + nameChangeReq = 'deviceNameChangeRequest', | ||
| 47 | + nameChangeResp = 'deviceNameChangeResponse', | ||
| 46 | 48 | ||
| 47 | propOrder = [ | 49 | propOrder = [ |
| 48 | - 'type', 'masterid', 'chassisid', | 50 | + 'id', 'type', 'masterid', 'chassisid', |
| 49 | 'mfr', 'hw', 'sw', 'protocol', 'serial' | 51 | 'mfr', 'hw', 'sw', 'protocol', 'serial' |
| 50 | ], | 52 | ], |
| 51 | friendlyProps = [ | 53 | friendlyProps = [ |
| 52 | - 'Type', 'Master ID', 'Chassis ID', | 54 | + 'URI', 'Type', 'Master ID', 'Chassis ID', |
| 53 | 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #' | 55 | 'Vendor', 'H/W Version', 'S/W Version', 'Protocol', 'Serial #' |
| 54 | ], | 56 | ], |
| 55 | portCols = [ | 57 | portCols = [ |
| ... | @@ -74,57 +76,52 @@ | ... | @@ -74,57 +76,52 @@ |
| 74 | div.on('click', closePanel); | 76 | div.on('click', closePanel); |
| 75 | } | 77 | } |
| 76 | 78 | ||
| 77 | - function getNameSpan() { | 79 | + function exitEditMode(nameH2, name) { |
| 78 | - return top.select('.name-div').select('.value'); | 80 | + nameH2.html(name); |
| 79 | - } | 81 | + nameH2.classed('editable', true); |
| 80 | - | 82 | + editingName = false; |
| 81 | - function nameValid(name) { | 83 | + ks.enableGlobalKeys(true); |
| 82 | - // TODO: guard against empty strings etc. | ||
| 83 | - return true; | ||
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | function editNameSave() { | 86 | function editNameSave() { |
| 87 | - var span = getNameSpan(), | 87 | + var nameH2 = top.select('h2'), |
| 88 | + id = $scope.panelData.id, | ||
| 89 | + val, | ||
| 88 | newVal; | 90 | newVal; |
| 89 | - if (editingName) { | ||
| 90 | - newVal = span.select('input').property('value'); | ||
| 91 | 91 | ||
| 92 | - $log.debug("TODO: Saving name change... to '" + newVal + "'"); | 92 | + if (editingName) { |
| 93 | - if (!nameValid(newVal)) { | 93 | + val = nameH2.select('input').property('value').trim(); |
| 94 | - return editNameCancel(); | 94 | + newVal = val || id; |
| 95 | - } | ||
| 96 | 95 | ||
| 97 | - // TODO: send event to server to set friendly name for device | 96 | + exitEditMode(nameH2, newVal); |
| 98 | $scope.panelData.name = newVal; | 97 | $scope.panelData.name = newVal; |
| 99 | - | 98 | + wss.sendEvent(nameChangeReq, { id: id, name: val }); |
| 100 | - span.html(newVal); | ||
| 101 | - span.classed('editable', true); | ||
| 102 | - editingName = false; | ||
| 103 | } | 99 | } |
| 104 | } | 100 | } |
| 105 | 101 | ||
| 106 | function editNameCancel() { | 102 | function editNameCancel() { |
| 107 | - var span = getNameSpan(); | ||
| 108 | if (editingName) { | 103 | if (editingName) { |
| 109 | - $log.debug("Canceling name change..."); | 104 | + exitEditMode(top.select('h2'), $scope.panelData.name); |
| 110 | - span.html($scope.panelData.name); | ||
| 111 | - span.classed('editable', true); | ||
| 112 | - editingName = false; | ||
| 113 | return true; | 105 | return true; |
| 114 | } | 106 | } |
| 115 | return false; | 107 | return false; |
| 116 | } | 108 | } |
| 117 | 109 | ||
| 118 | function editName() { | 110 | function editName() { |
| 119 | - $log.log('editName() .. editing=' + editingName); | 111 | + var nameH2 = top.select('h2'), |
| 120 | - var span = getNameSpan(); | 112 | + tf, el; |
| 113 | + | ||
| 121 | if (!editingName) { | 114 | if (!editingName) { |
| 122 | - editingName = true; | 115 | + nameH2.classed('editable', false); |
| 123 | - span.classed('editable', false); | 116 | + nameH2.html(''); |
| 124 | - span.html(''); | 117 | + tf = nameH2.append('input').classed('name-input', true) |
| 125 | - span.append('input').classed('name-input', true) | ||
| 126 | .attr('type', 'text') | 118 | .attr('type', 'text') |
| 127 | .attr('value', $scope.panelData.name); | 119 | .attr('value', $scope.panelData.name); |
| 120 | + el = tf[0][0]; | ||
| 121 | + el.focus(); | ||
| 122 | + el.select(); | ||
| 123 | + editingName = true; | ||
| 124 | + ks.enableGlobalKeys(false); | ||
| 128 | } | 125 | } |
| 129 | } | 126 | } |
| 130 | 127 | ||
| ... | @@ -132,14 +129,6 @@ | ... | @@ -132,14 +129,6 @@ |
| 132 | return editNameCancel() || closePanel(); | 129 | return editNameCancel() || closePanel(); |
| 133 | } | 130 | } |
| 134 | 131 | ||
| 135 | - function setUpEditableName(top) { | ||
| 136 | - var div = top.append('div').classed('name-div', true); | ||
| 137 | - | ||
| 138 | - div.append('span').classed('label', true); | ||
| 139 | - div.append('span').classed('value editable', true) | ||
| 140 | - .on('click', editName); | ||
| 141 | - } | ||
| 142 | - | ||
| 143 | function setUpPanel() { | 132 | function setUpPanel() { |
| 144 | var container, closeBtn, tblDiv; | 133 | var container, closeBtn, tblDiv; |
| 145 | detailsPanel.empty(); | 134 | detailsPanel.empty(); |
| ... | @@ -150,9 +139,7 @@ | ... | @@ -150,9 +139,7 @@ |
| 150 | closeBtn = top.append('div').classed('close-btn', true); | 139 | closeBtn = top.append('div').classed('close-btn', true); |
| 151 | addCloseBtn(closeBtn); | 140 | addCloseBtn(closeBtn); |
| 152 | iconDiv = top.append('div').classed('dev-icon', true); | 141 | iconDiv = top.append('div').classed('dev-icon', true); |
| 153 | - top.append('h2'); | 142 | + top.append('h2').classed('editable', true).on('click', editName); |
| 154 | - | ||
| 155 | - setUpEditableName(top); | ||
| 156 | 143 | ||
| 157 | tblDiv = top.append('div').classed('top-tables', true); | 144 | tblDiv = top.append('div').classed('top-tables', true); |
| 158 | tblDiv.append('div').classed('left', true).append('table'); | 145 | tblDiv.append('div').classed('left', true).append('table'); |
| ... | @@ -184,11 +171,11 @@ | ... | @@ -184,11 +171,11 @@ |
| 184 | .append('tbody'); | 171 | .append('tbody'); |
| 185 | 172 | ||
| 186 | is.loadEmbeddedIcon(iconDiv, details._iconid_type, 40); | 173 | is.loadEmbeddedIcon(iconDiv, details._iconid_type, 40); |
| 187 | - top.select('h2').html(details.id); | 174 | + top.select('h2').html(details.name); |
| 188 | 175 | ||
| 189 | propOrder.forEach(function (prop, i) { | 176 | propOrder.forEach(function (prop, i) { |
| 190 | // properties are split into two tables | 177 | // properties are split into two tables |
| 191 | - addProp(i < 3 ? leftTbl : rightTbl, i, details[prop]); | 178 | + addProp(i < 4 ? leftTbl : rightTbl, i, details[prop]); |
| 192 | }); | 179 | }); |
| 193 | } | 180 | } |
| 194 | 181 | ||
| ... | @@ -258,6 +245,13 @@ | ... | @@ -258,6 +245,13 @@ |
| 258 | $scope.$apply(); | 245 | $scope.$apply(); |
| 259 | } | 246 | } |
| 260 | 247 | ||
| 248 | + function respNameCb(data) { | ||
| 249 | + if (data.warn) { | ||
| 250 | + $log.warn(data.warn, data.id); | ||
| 251 | + top.select('h2').html(data.id); | ||
| 252 | + } | ||
| 253 | + } | ||
| 254 | + | ||
| 261 | function createDetailsPane() { | 255 | function createDetailsPane() { |
| 262 | detailsPanel = ps.createPanel(pName, { | 256 | detailsPanel = ps.createPanel(pName, { |
| 263 | width: wSize.width, | 257 | width: wSize.width, |
| ... | @@ -276,21 +270,26 @@ | ... | @@ -276,21 +270,26 @@ |
| 276 | .controller('OvDeviceCtrl', | 270 | .controller('OvDeviceCtrl', |
| 277 | ['$log', '$scope', '$location', 'TableBuilderService', 'FnService', | 271 | ['$log', '$scope', '$location', 'TableBuilderService', 'FnService', |
| 278 | 'MastService', 'PanelService', 'WebSocketService', 'IconService', | 272 | 'MastService', 'PanelService', 'WebSocketService', 'IconService', |
| 279 | - 'NavService', | 273 | + 'NavService', 'KeyService', |
| 280 | 274 | ||
| 281 | function (_$log_, _$scope_, _$location_, | 275 | function (_$log_, _$scope_, _$location_, |
| 282 | - tbs, _fs_, _mast_, _ps_, _wss_, _is_, _ns_) { | 276 | + tbs, _fs_, _mast_, _ps_, _wss_, _is_, _ns_, _ks_) { |
| 277 | + var params, | ||
| 278 | + handlers = {}; | ||
| 279 | + | ||
| 283 | $log = _$log_; | 280 | $log = _$log_; |
| 284 | $scope = _$scope_; | 281 | $scope = _$scope_; |
| 285 | - $location = _$location_; | 282 | + $loc = _$location_; |
| 286 | fs = _fs_; | 283 | fs = _fs_; |
| 287 | mast = _mast_; | 284 | mast = _mast_; |
| 288 | ps = _ps_; | 285 | ps = _ps_; |
| 289 | wss = _wss_; | 286 | wss = _wss_; |
| 290 | is = _is_; | 287 | is = _is_; |
| 291 | ns = _ns_; | 288 | ns = _ns_; |
| 292 | - var params = $location.search(), | 289 | + ks = _ks_; |
| 293 | - handlers = {}; | 290 | + |
| 291 | + params = $loc.search(); | ||
| 292 | + | ||
| 294 | $scope.panelData = {}; | 293 | $scope.panelData = {}; |
| 295 | $scope.flowTip = 'Show flow view for selected device'; | 294 | $scope.flowTip = 'Show flow view for selected device'; |
| 296 | $scope.portTip = 'Show port view for selected device'; | 295 | $scope.portTip = 'Show port view for selected device'; |
| ... | @@ -298,6 +297,7 @@ | ... | @@ -298,6 +297,7 @@ |
| 298 | 297 | ||
| 299 | // details panel handlers | 298 | // details panel handlers |
| 300 | handlers[detailsResp] = respDetailsCb; | 299 | handlers[detailsResp] = respDetailsCb; |
| 300 | + handlers[nameChangeResp] = respNameCb; | ||
| 301 | wss.bindHandlers(handlers); | 301 | wss.bindHandlers(handlers); |
| 302 | 302 | ||
| 303 | // query for if a certain device needs to be highlighted | 303 | // query for if a certain device needs to be highlighted | ... | ... |
-
Please register or login to post a comment