Skip to content

Commit

Permalink
elm
Browse files Browse the repository at this point in the history
  • Loading branch information
3v0k4 committed Jun 14, 2019
1 parent a791c80 commit bbb7a7c
Show file tree
Hide file tree
Showing 69 changed files with 1,026 additions and 1,837 deletions.
5 changes: 0 additions & 5 deletions README.md
Expand Up @@ -68,11 +68,6 @@ yarn run elm-format --validate app/javascript/elm

Read more [here](doc/api.md).

## Assets version bumping

Whenever changing code tounching google maps, the `data-version` attribute in `app/views/layouts/map.html.haml` should
be bumped. This ensures that the assets will reload correctly.

## Importing a big db dump to a server, i.e. staging

For restoring a big db dump you can try to opitimize a process by changing the database configuration temporarily.
Expand Down
19 changes: 19 additions & 0 deletions app/assets/stylesheets/application.css
Expand Up @@ -167,3 +167,22 @@
width: 100px;
background-color: red;
}

.filters-tag {
display: inline-block;
background-color: #ccc;
color: #525151;
margin-right: 10px;
font-weight: normal;
margin-bottom: 5px;
padding: 3px 8px 3px 7px;
border-radius: 15px;
font-size: 12px;
}

.filters-tag-close {
width: 8px;
height: 8px;
padding: 0 0 0 12px;
background: url("close-icon.svg") no-repeat right center;
}
25 changes: 2 additions & 23 deletions app/controllers/maps_controller.rb
@@ -1,26 +1,5 @@
# AirCasting - Share your Air!
# Copyright (C) 2011-2012 HabitatMap, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# You can contact the authors by email at <info@habitatmap.org>

class MapsController < ApplicationController
layout 'map'

def show
@map_state = params[:map_state] || "{}"
ActiveSupport::JSON.decode(@map_state) rescue raise NotAcceptable
def index
render layout: "map"
end
end
23 changes: 0 additions & 23 deletions app/controllers/yellow_controller.rb

This file was deleted.

20 changes: 1 addition & 19 deletions app/javascript/angular/code/aircasting.js
@@ -1,25 +1,7 @@
import constants from './constants';

angular.module('google', []);
angular.module('aircasting', ['ngRoute', 'ngCookies', "google"], [ "$routeProvider", function($routeProvider){
const v = $("body").data("version");

$routeProvider.when(constants.mobileMapRoute,
{templateUrl: 'partials/mobile_sessions_map.html?v=' + v,
controller: 'MobileSessionsMapCtrl', reloadOnSearch: false,
resolve: {
sensorsList: ['$http', function($http) {return $http.get('/api/sensors', {cache: true}).then(function(response){ return response.data}) }]
}
});
$routeProvider.when(constants.fixedMapRoute,
{templateUrl: 'partials/fixed_sessions_map.html?v=' + v,
controller: 'FixedSessionsMapCtrl', reloadOnSearch: false,
resolve: {
sensorsList: ['$http', function($http) {return $http.get('/api/sensors', {cache: true}).then(function(response){ return response.data}) }]
}
});
$routeProvider.otherwise({redirectTo: '/map_sessions'});
}]);
angular.module('aircasting', ['ngCookies', "google"]);

angular.module('aircasting').config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/angular/code/constants.js
@@ -1,5 +1,5 @@
export default {
fixedMapRoute: '/map_fixed_sessions',
mobileMapRoute: '/map_sessions',
fixedMapRoute: '/fixed_map',
mobileMapRoute: '/mobile_map',
fixedSession: "Fixed"
};
@@ -1,7 +1,5 @@
import _ from 'underscore';
import { Elm } from '../../../elm/src/FixedSessionFilters.elm';
import moment from 'moment'
import { buildAvailableParameters } from '../services/_sensors'

import * as FiltersUtils from '../filtersUtils'

Expand All @@ -11,29 +9,23 @@ export const FixedSessionsMapCtrl = (
heat,
map,
sensors,
expandables,
storage,
fixedSessions,
versioner,
storageEvents,
singleFixedSession,
functionBlocker,
$window,
$location,
rectangles,
infoWindow,
$http,
sensorsList
$http
) => {
sensors.setSensors(sensorsList);
sensors.setSensors($window.__sensors);

$scope.setDefaults = function() {
$scope.versioner = versioner;
$scope.params = params;
$scope.storage = storage;
$scope.storageEvents = storageEvents;
$scope.sensors = sensors;
$scope.expandables = expandables;
$scope.sessions = fixedSessions;
$scope.singleSession = singleFixedSession;
$scope.$window = $window;
Expand All @@ -50,9 +42,6 @@ export const FixedSessionsMapCtrl = (
$scope.$digest();
});
}
_.each(['sensor', 'location', 'usernames'], function(name) {
$scope.expandables.show(name);
});

const sensorId = params
.get('data', { sensorId: sensors.defaultSensorId })
Expand Down Expand Up @@ -106,23 +95,7 @@ export const FixedSessionsMapCtrl = (

if (process.env.NODE_ENV !== 'test') {
angular.element(document).ready(function () {
const node = document.getElementById('newFixedFilters');

const timeRange = {
timeFrom: $scope.params.get('data').timeFrom,
timeTo: $scope.params.get('data').timeTo,
};

const flags = {
parametersList: buildAvailableParameters(sensorsList),
selectedParameter: sensors.findParameterForSensor(sensors.selected()).id,
location: $scope.params.get('data').location || "",
tags: $scope.params.get('data').tags.split(', ').filter((tag) => tag !== "") || [],
profiles: $scope.params.get('data').usernames.split(', ').filter((tag) => tag !== "") || [],
timeRange
};

const elmApp = Elm.FixedSessionFilters.init({ node: node, flags: flags });
const elmApp = window.__elmApp;

elmApp.ports.selectParameter.subscribe(parameter =>{
const oldValue = sensors.selectedParameter;
Expand All @@ -143,13 +116,13 @@ export const FixedSessionsMapCtrl = (

FiltersUtils.setupAutocomplete(
(selectedValue) => elmApp.ports.profileSelected.send(selectedValue)
, "profiles-search"
, "profile-names"
, "/autocomplete/usernames"
)

FiltersUtils.setupAutocomplete(
(selectedValue) => elmApp.ports.tagSelected.send(selectedValue)
, "tags-search"
, "tags"
, "/autocomplete/tags"
)

Expand Down
@@ -1,35 +1,28 @@
import _ from 'underscore';
import { Elm } from '../../../elm/src/MobileSessionsFilters.elm';
import moment from 'moment'
import * as FiltersUtils from '../filtersUtils'
import { buildAvailableParameters } from '../services/_sensors'

export const MobileSessionsMapCtrl = (
$scope,
params,
map,
sensors,
expandables,
storage,
mobileSessions,
versioner,
storageEvents,
singleMobileSession,
functionBlocker,
$window,
infoWindow,
sensorsList,
sessionsUtils
) => {
sensors.setSensors(sensorsList);
sensors.setSensors($window.__sensors);

$scope.setDefaults = function() {
$scope.versioner = versioner;
$scope.params = params;
$scope.storage = storage;
$scope.storageEvents = storageEvents;
$scope.sensors = sensors;
$scope.expandables = expandables;
$scope.sessions = mobileSessions;
$scope.singleSession = singleMobileSession;
$scope.$window = $window;
Expand All @@ -47,10 +40,6 @@ export const MobileSessionsMapCtrl = (
});
}

['sensor', 'heatLegend'].forEach(function(name) {
$scope.expandables.show(name);
});

const sensorId = params
.get('data', { sensorId: sensors.defaultSensorId })
.sensorId;
Expand Down Expand Up @@ -105,25 +94,7 @@ export const MobileSessionsMapCtrl = (

if (process.env.NODE_ENV !== 'test') {
angular.element(document).ready(function () {
const node = document.getElementById('newMobileFilters');

const timeRange = {
timeFrom: $scope.params.get('data').timeFrom,
timeTo: $scope.params.get('data').timeTo,
};

const flags = {
parametersList: buildAvailableParameters(sensorsList),
selectedParameter: sensors.findParameterForSensor(sensors.selected()).id,
isCrowdMapOn: $scope.params.get('data').crowdMap || false,
crowdMapResolution: $scope.params.get('data').gridResolution || 25,
location: $scope.params.get('data').location || "",
tags: $scope.params.get('data').tags.split(', ').filter((tag) => tag !== "") || [],
profiles: $scope.params.get('data').usernames.split(', ').filter((tag) => tag !== "") || [],
timeRange
};

const elmApp = Elm.MobileSessionsFilters.init({ node: node, flags: flags });
const elmApp = window.__elmApp;

elmApp.ports.selectParameter.subscribe(parameter =>{
const oldValue = sensors.selectedParameter;
Expand Down Expand Up @@ -154,13 +125,13 @@ export const MobileSessionsMapCtrl = (

FiltersUtils.setupAutocomplete(
(selectedValue) => elmApp.ports.profileSelected.send(selectedValue)
, "profiles-search"
, "profile-names"
, "/autocomplete/usernames"
)

FiltersUtils.setupAutocomplete(
(selectedValue) => elmApp.ports.tagSelected.send(selectedValue)
, "tags-search"
, "tags"
, "/autocomplete/tags"
)

Expand Down
19 changes: 8 additions & 11 deletions app/javascript/angular/code/controllers/_sessions_list_ctrl.js
@@ -1,6 +1,5 @@
import _ from 'underscore';
import { formatSessionForList } from '../values/session'
import { Elm } from '../../../elm/src/SessionsList.elm';

export const SessionsListCtrl = (
$scope,
Expand All @@ -11,12 +10,10 @@ export const SessionsListCtrl = (
$window,
drawSession,
markerSelected,
updateCrowdMapLayer,
$location
updateCrowdMapLayer
) => {
let sessions;
let singleSession;
let elmApp;
const elmApp = $window.__elmApp;
const CANNOT_SELECT_MULTIPLE_SESSIONS = "You can't select multiple sessions";

$scope.setDefaults = function() {
Expand All @@ -27,7 +24,6 @@ export const SessionsListCtrl = (
$scope.page = 0;
$scope.markerSelected = markerSelected;
$window.sessions = sessions = $scope.sessions;
$window.singleSession = singleSession = $scope.singleSession;
$scope.sessionsForList = [];

// prolly this can be removed
Expand Down Expand Up @@ -88,7 +84,7 @@ export const SessionsListCtrl = (
$scope.$watch("newSessionsForList()", function(newSessions, oldSessions) {
console.log("newSessionsForList()", newSessions, oldSessions);
$scope.sessionsForList = newSessions;
if (elmApp) elmApp.ports.updateSessions.send(newSessions.map(formatSessionForElm));
elmApp.ports.updateSessions.send(newSessions.map(formatSessionForElm));
}, true);

$scope.$on('markerSelected', function(event, data){
Expand All @@ -112,6 +108,11 @@ export const SessionsListCtrl = (
}
};

$scope.$watch("params.get('selectedSessionIds')", function(newIds, oldIds) {
console.log("watch - params.get('selectedSessionIds')");
sessions.sessionsChanged(newIds, oldIds);
}, true);

$scope.canExportSessions = function() {
return (true === params.get('didSessionsSearch', false) && sessions.get().length > 0);
};
Expand Down Expand Up @@ -140,10 +141,6 @@ export const SessionsListCtrl = (

if (process.env.NODE_ENV !== 'test') {
angular.element(document).ready(() => {
const node = document.getElementById('sessions-bottom-elm');
const flags = $scope.sessions.get().map(formatSessionForList).map(formatSessionForElm);
elmApp = Elm.SessionsList.init({ node, flags });

elmApp.ports.checkedSession.subscribe(({ selected, deselected }) => {
if (deselected) $scope.toggleSession(deselected, true);
if (selected) $scope.toggleSession(selected, true);
Expand Down
Expand Up @@ -6,18 +6,14 @@ angular.module('aircasting').controller('FixedSessionsMapCtrl', [
'heat',
'map',
'sensors',
'expandables',
'storage',
'fixedSessions',
'versioner',
'storageEvents',
'singleFixedSession',
'functionBlocker',
'$window',
'$location',
'rectangles',
'infoWindow',
'$http',
'sensorsList',
FixedSessionsMapCtrl
]);

0 comments on commit bbb7a7c

Please sign in to comment.