Skip to content

Commit

Permalink
Removing kits. Improve Device and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
oscgonfer committed Feb 28, 2024
1 parent 7cbb2d4 commit 034b320
Show file tree
Hide file tree
Showing 21 changed files with 335 additions and 343 deletions.
1 change: 0 additions & 1 deletion src/app/app.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
controllerAs: 'vm',
resolve: {
belongsToUser: belongsToUser,
// TODO - Refactor variable
kit: ['device', 'FullDevice', '$stateParams', function(device, FullDevice, $stateParams) {
return device.getDevice($stateParams.id)
.then(kit => new FullDevice(kit));
Expand Down
62 changes: 34 additions & 28 deletions src/app/components/kit/editKit/editKit.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@

EditKitController.$inject = ['$scope', '$element', '$location', '$timeout', '$state',
'animation','auth','device', 'tag', 'alert', 'step', '$stateParams', 'FullDevice'];
function EditKitController($scope, $element, $location, $timeout, $state, animation, auth,
device, tag, alert, step, $stateParams, FullDevice) {
function EditKitController($scope, $element, $location, $timeout, $state, animation, auth, device, tag, alert, step, $stateParams, FullDevice) {

var vm = this;

// WHAIT INTERVAL FOR USER FEEDBACK and TRANSITIONS (This will need to change)
// WAIT INTERVAL FOR USER FEEDBACK and TRANSITIONS (This will need to change)
var timewait = {
long: 5000,
normal: 2000,
Expand All @@ -55,7 +54,7 @@

// FORM INFO
vm.deviceForm = {};
vm.deviceData = undefined;
vm.device = undefined;

$scope.clearSearchTerm = function() {
$scope.searchTerm = '';
Expand Down Expand Up @@ -88,47 +87,50 @@
/////////////////

function initialize() {
var kitID = $stateParams.id;
var deviceID = $stateParams.id;

animation.viewLoaded();
getTags();

if (!kitID || kitID === ''){
if (!deviceID || deviceID === ''){
return;
}
device.getDevice(kitID)
device.getDevice(deviceID)
.then(function(deviceData) {
vm.deviceData = new FullDevice(deviceData);
vm.device = new FullDevice(deviceData);
vm.userRole = auth.getCurrentUser().data.role;
vm.deviceForm = {
name: vm.deviceData.name,
exposure: findExposureFromLabels(vm.deviceData.labels),
name: vm.device.name,
exposure: findExposureFromLabels(vm.device.systemTags),
location: {
lat: vm.deviceData.latitude,
lng: vm.deviceData.longitude,
lat: vm.device.location.latitude,
lng: vm.device.location.longitude,
zoom: 16
},
is_private: deviceData.is_private,
notify_low_battery: deviceData.notify_low_battery,
notify_stopped_publishing: deviceData.notify_stopped_publishing,
tags: vm.deviceData.userTags,
postprocessing: deviceData.postprocessing,
description: vm.deviceData.description
is_private: vm.device.isPrivate,
notify_low_battery: vm.device.notifications.lowBattery,
notify_stopped_publishing: vm.device.notifications.stopPublishing,
tags: vm.device.userTags,
postprocessing: vm.device.postProcessing,
description: vm.device.description
// hardware: vm.device.hardware
};
vm.markers = {
main: {
lat: vm.deviceData.latitude,
lng: vm.deviceData.longitude,
lat: vm.device.location.latitude,
lng: vm.device.location.longitude,
draggable: true
}
};
// TODO - Refactor. Change based on new names for versions after refactor
if(!vm.deviceData.version || vm.deviceData.version.id === 2 || vm.deviceData.version.id === 3){
vm.setupAvailable = true;
}

vm.macAddress = vm.deviceData.macAddress;

// TODO: Refactor. Change based on new names for versions after refactor
// This needs to be available in world_map as well
// Double Check
if (vm.device.hardware.info) {
vm.macAddress = vm.device.hardware.info.mac;
} else {
vm.macAddress = null;
}
});
}

Expand Down Expand Up @@ -174,7 +176,9 @@
notify_low_battery: vm.deviceForm.notify_low_battery,
notify_stopped_publishing: vm.deviceForm.notify_stopped_publishing,
/*jshint camelcase: false */
user_tags: joinSelectedTags()
user_tags: joinSelectedTags(),
// TODO: Refactor
// hardware: vm.deviceForm.hardware
};

if(!vm.macAddress || vm.macAddress === ''){
Expand All @@ -191,9 +195,10 @@
throw new Error('[Client:error] ' + message);
}

device.updateDevice(vm.deviceData.id, data)
device.updateDevice(vm.device.id, data)
.then(
function() {
// TODO: Refactor Check
if (!vm.macAddress && $stateParams.step === 2) {
alert.info.generic('Your kit was successfully updated but you will need to register the Mac Address later 🔧');
} else if (next){
Expand Down Expand Up @@ -257,6 +262,7 @@
}

function backToProfile(){
// TODO: Refactor Check
if (!vm.macAddress && $stateParams.step === 2) {
alert.info.generic('Remember you will need to register the Mac Address later 🔧');
$timeout(toProfile, timewait.normal);
Expand Down
141 changes: 75 additions & 66 deletions src/app/components/kit/editKit/editKit.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,48 @@
<section class="timeline" flex="1" layout="row" layout-align="center center">
<div class="timeline_container" layout="row" layout-align="space-between center">
<div layout="row" layout-align="start center">
<div class="timeline_stepCircle"
<!-- TODO: Refactor - This was removed -->
<!-- <div class="timeline_stepCircle"
ng-class="{'is-on':vm.step===1, 'is-off':vm.step!==1}"
layout="row" layout-align="center center">
1
</div>
<md-button ng-click="vm.goToStep(1)" class="timeline_stepName">
</div> -->
<!-- <md-button ng-click="vm.goToStep(1)" class="timeline_stepName">
Kit data
</md-button>
<div ng-if="vm.setupAvailable" class="timeline_line timeline_line_small"></div>
<div ng-if="vm.setupAvailable" layout="row" layout-align="start center">
</md-button> -->
<h2 class="timeline-title timeline-title">
Kit Data
</div>
<!-- TODO: Refactor - This was removed -->
<!-- <div ng-if="vm.deviceData.isLegacy" class="timeline_line timeline_line_small"></div>
<div ng-if="vm.deviceData.isLegacy" layout="row" layout-align="start center">
<div class="timeline_stepCircle"
ng-class="{'is-on':vm.step===2, 'is-off':vm.step!==2}"
layout="row" layout-align="center center"
ng-class="{'is-on': vm.step === 2, 'is-off': vm.step !== 2}">
2
</div>
<md-button ng-if="vm.setupAvailable" ng-click="vm.goToStep(2)" class="timeline_stepName">
<md-button ng-if="vm.deviceData.isLegacy" ng-click="vm.goToStep(2)" class="timeline_stepName">
Set up
</md-button>
</div>
</div> -->
</div>
<md-button style="margin-left: auto" class="md-flat md-primary timeline_buttonBack" ng-click="vm.backToProfile()">Back to Profile</md-button>
<md-button style="margin-left: 20px" class="md-flat md-primary timeline_buttonSave" ng-click="vm.submitFormAndKit()">Save</md-button>
<!-- TODO: Cosmetic Make nicer -->
<!-- <md-button style="margin-left: auto" class="md-flat md-primary timeline_buttonBack" ng-click="vm.backToDevice()">Back to Device</md-button> -->
<md-button class="md-flat md-primary timeline_buttonBack btn-round-new" ng-click="vm.backToProfile()">Back<span class="timeline-btn-extra"> to Profile</span></md-button>
<md-button class="md-flat md-primary timeline_buttonSave btn-round-new" ng-click="vm.submitFormAndKit()">Save</md-button>
</div>
</section>
<section class="timeline_content" flex="1">

<section ng-show="vm.step === 1">
<form>
<section class="bg-white" layout-padding div layout="row" layout-xs="column" layout-align="space-around start">
<section class="bg-white relaxed-layout" layout-padding div layout="row" layout-xs="column" layout-align="space-around start">
<div flex-gt-xs="50">
<div layout="row">
<div class="">
<h2>Basic information</h2>
<small>Please, provide kit basic info. That includes a name and exposure</small>
<small>Want to change your kit's name? Or perhahps say something nice about it in the description?
<br>Don't forget about the exposure!</small>
</div>
</div>
</div>
Expand All @@ -46,6 +53,10 @@ <h2>Basic information</h2>
<label>Kit Name</label>
<input type="text" class="font-roboto-condensed" ng-model="vm.deviceForm.name">
</md-input-container>
<md-input-container flex="100" flex-gt-md="50">
<label>Say something nice about your kit, what is it for?</label>
<textarea class="font-roboto-condensed" type="text" ng-model="vm.deviceForm.description" placeholder="Describe your kit" md-maxlength="120"></textarea>
</md-input-container>
<div layout="row" layout-align="space-between start">
<div class="" layout="row" layout-align="start center">
<label class="mr-10">Exposure:</label>
Expand All @@ -56,33 +67,70 @@ <h2>Basic information</h2>
</div>
</div>
</div>
</section>
</section>

<section layout="row" layout-xs="column" layout-align="space-around start" layout-padding>
<section class="form_blockMap relaxed-layout" layout="row" layout-xs="column" layout-align="space-around start" layout-padding>
<div flex-gt-xs="50">
<div layout="row">
<div>
<h2>Kit location</h2>
<small>You can adjust the location by dragging the marker on the map.</small>
</div>
</div>
</div>
<div flex="50">
<div class="form_blockInput_button" ng-if="!vm.deviceForm.location.lat && !vm.deviceForm.location.lng">
<div class="form_blockInput_container" layout="row" layout-align="center center">
<md-button class="md-flat btn-cyan" ng-click="vm.getLocation()">Get your location</md-button>
</div>
</div>
<div class="form_blockInput_map" ng-if="vm.deviceForm.location.lat && vm.deviceForm.location.lng">
<leaflet center="vm.deviceForm.location" defaults="vm.defaults" markers="vm.markers" tiles="vm.tiles" width="100%" height="100%"></leaflet>
</div>
</div>
</section>

<!-- TODO: Refactor Can this be pushed? -->
<!-- <section layout="row" layout-xs="column" layout-align="space-around start" layout-padding>
<div flex-gt-xs="50">
<div>
<h2>About the hardware</h2>
<small>If you have some custom kit, you can tell us here (i.e. SCK 2.2 + CO2)</small>
</div>
</div>
<div flex-gt-xs="50">
<div layout="row">
<md-input-container flex="100" flex-gt-md="50">
<label>Hardware Description</label>
<textarea class="font-roboto-condensed" type="text" ng-model="vm.deviceForm.hardware" placeholder="Describe your hardware" md-maxlength="30"></textarea>
</md-input-container>
</div>
</div>
</section> -->
<section class="bg-white relaxed-layout" layout="row" layout-xs="column" layout-align="space-around start" layout-padding ng-if="vm.userRole === 'researcher' || vm.userRole === 'admin'">
<div flex-gt-xs="50">
<div layout="row">
<div class="">
<h2>Open Data</h2>
<small>We advocate for open data and open science! However, some times your devices might be collecting potential personal data (i.e. your exact location, by GPS using in your bike) and you might consider changing how others can access your data
<h2>Open data</h2>
<small>Sometimes, your devices might be collecting sensitive personal data (i.e. your exact location or by GPS using in your bike).<br>Check the box in case you want to prevent others from accesssing your data.
</small>
</div>
</div>
</div>
<div flex-gt-xs="50">
<div class="" layout="column">
<p>Manage how others can access your data:</p>
<md-checkbox ng-if="vm.userRole === 'researcher' || vm.userRole === 'admin'" ng-model="vm.deviceForm.is_private">
<md-checkbox ng-model="vm.deviceForm.is_private">
<label>Make this device private</label>
</md-checkbox>
</div>
</div>
</section>

<section layout="row" layout-xs="column" layout-align="space-around start" layout-padding>
<section class="relaxed-layout" layout="row" layout-xs="column" layout-align="space-around start" layout-padding>
<div flex-gt-xs="50">
<div layout="row">
<div class="">
<h2>Notification</h2>
<h2>Notifications</h2>
<small>Manage your notifications</small>
</div>
</div>
Expand All @@ -100,28 +148,7 @@ <h2>Notification</h2>
</div>
</section>

<section class="form_blockMap bg-white" layout="row" layout-xs="column" layout-align="space-around start" layout-padding>
<div flex-gt-xs="50">
<div layout="row">
<div>
<h2>Kit location</h2>
<small>You can adjust the location by dragging the marker on the map.</small>
</div>
</div>
</div>
<div flex="50">
<div class="form_blockInput_button" ng-if="!vm.deviceForm.location.lat && !vm.deviceForm.location.lng">
<div class="form_blockInput_container" layout="row" layout-align="center center">
<md-button class="md-flat btn-cyan" ng-click="vm.getLocation()">Get your location</md-button>
</div>
</div>
<div class="form_blockInput_map" ng-if="vm.deviceForm.location.lat && vm.deviceForm.location.lng">
<leaflet center="vm.deviceForm.location" defaults="vm.defaults" markers="vm.markers" tiles="vm.tiles" width="100%" height="100%"></leaflet>
</div>
</div>
</section>

<section layout="row" layout-xs="column" layout-align="space-around start" layout-padding>
<section class="bg-white relaxed-layout" layout="row" layout-xs="column" layout-align="space-around start" layout-padding>
<div flex-gt-xs="50">
<h2>Kit tags</h2>
<small>Kits can be grouped by tags. Choose from the available tags or submit a tag request on the <a href="https://forum.smartcitizen.me/" target="_blank">Forum</a>.</small>
Expand All @@ -148,25 +175,7 @@ <h2>Kit tags</h2>
</md-input-container>
</div>
</section>

<section class="bg-white" layout="row" layout-xs="column" layout-align="space-around start" layout-padding>
<div flex-gt-xs="50">
<div>
<h2>Kit description</h2>
<small>Say something nice about your kit. Why is it for? Is this part of any kind of project? Whatever :)</small>
</div>
</div>
<div flex-gt-xs="50">
<div layout="row">
<md-input-container flex="100" flex-gt-md="50">
<label>Description</label>
<textarea class="font-roboto-condensed" type="text" ng-model="vm.deviceForm.description" placeholder="Describe your kit" md-maxlength="120"></textarea>
</md-input-container>
</div>
</div>
</section>

<section class="" layout-gt-sm="row" layout="column" layout-padding>
<section class="relaxed-layout" layout-gt-sm="row" layout="column" layout-padding>
<div flex="100">
<h2>Postprocessing info</h2>
<small>
Expand All @@ -187,15 +196,15 @@ <h2>Postprocessing info</h2>
</div>
</section>
</form>
<div class="mt-50" layout="row" layout-align="center start" layout-margin layout-padding>
<!-- <div class="mt-50" layout="row" layout-align="center start" layout-margin layout-padding>
<md-button class="fillwidth md-raised md-accent" ng-click="vm.submitFormAndKit()">Save</md-button>
</div>
</div> -->
<div layout layout-padding layout-margin>
<md-button ng-show="vm.setupAvailable" class="fillwidth md-raised md-primary mb-30" ng-click="vm.submitFormAndNext()">Open kit set up</md-button>
<md-button ng-show="vm.deviceData.isLegacy" class="fillwidth md-raised md-primary mb-30" ng-click="vm.submitFormAndNext()">Open kit set up</md-button>
</div>
</section>

<section ng-if="vm.step === 2 && vm.setupAvailable">
<section ng-if="vm.step === 2 && vm.deviceData.isLegacy">
<form>
<section class="isEven">
<div layout="row" layout-xs="column" layout-align="start start" layout-padding>
Expand Down
Loading

0 comments on commit 034b320

Please sign in to comment.