Skip to content
Permalink
Browse files

elm

  • Loading branch information...
3v0k4 committed Apr 2, 2019
1 parent a791c80 commit bbb7a7c74a02e56971f680704058609b6f6c8496
Showing with 1,026 additions and 1,837 deletions.
  1. +0 −5 README.md
  2. +19 −0 app/assets/stylesheets/application.css
  3. +2 −23 app/controllers/maps_controller.rb
  4. +0 −23 app/controllers/yellow_controller.rb
  5. +1 −19 app/javascript/angular/code/aircasting.js
  6. +2 −2 app/javascript/angular/code/constants.js
  7. +5 −32 app/javascript/angular/code/controllers/_fixed_sessions_map_ctrl.js
  8. +4 −33 app/javascript/angular/code/controllers/_mobile_sessions_map_ctrl.js
  9. +8 −11 app/javascript/angular/code/controllers/_sessions_list_ctrl.js
  10. +0 −4 app/javascript/angular/code/controllers/fixed_sessions_map_ctrl.js
  11. +0 −18 app/javascript/angular/code/controllers/heat_ctrl.js
  12. +0 −3 app/javascript/angular/code/controllers/mobile_sessions_map_ctrl.js
  13. +0 −34 app/javascript/angular/code/controllers/panel_ctrl.js
  14. +0 −3 app/javascript/angular/code/controllers/sessions_graph_ctrl.js
  15. +0 −1 app/javascript/angular/code/controllers/sessions_list_ctrl.js
  16. +0 −14 app/javascript/angular/code/directives/heat_background.js
  17. +0 −28 app/javascript/angular/code/directives/http_spinner.js
  18. +2 −2 app/javascript/angular/code/filtersUtils.js
  19. +3 −3 app/javascript/angular/code/services/_fixed_sessions.js
  20. +4 −4 app/javascript/angular/code/services/_mobile_sessions.js
  21. +0 −4 app/javascript/angular/code/services/_storage.js
  22. +4 −4 app/javascript/angular/code/services/_update_crowd_map_layer.js
  23. +0 −22 app/javascript/angular/code/services/expandables.js
  24. +0 −1 app/javascript/angular/code/services/fixed_sessions.js
  25. +2 −5 app/javascript/angular/code/services/graph.js
  26. +3 −3 app/javascript/angular/code/services/http_spinner_interceptor.js
  27. +1 −1 app/javascript/angular/code/services/mobile_sessions.js
  28. +0 −11 app/javascript/angular/code/services/single_fixed_session.js
  29. +0 −13 app/javascript/angular/code/services/single_mobile_session.js
  30. +0 −80 app/javascript/angular/code/services/storage_events.js
  31. +1 −1 app/javascript/angular/code/services/update_crowd_map_layer.js
  32. +0 −8 app/javascript/angular/code/services/utils.js
  33. +0 −2 app/javascript/angular/tests/_build_query_params_for_crowd_map_layer.test.js
  34. +5 −5 app/javascript/angular/tests/_fixed_sessions.test.js
  35. +2 −2 app/javascript/angular/tests/_fixed_sessions_map_ctrl.test.js
  36. +5 −5 app/javascript/angular/tests/_mobile_sessions.test.js
  37. +3 −16 app/javascript/angular/tests/_mobile_sessions_map_ctrl.test.js
  38. +10 −10 app/javascript/angular/tests/_update_crowd_map_layer.test.js
  39. +17 −0 app/javascript/elm/src/Data/Session.elm
  40. +0 −237 app/javascript/elm/src/FixedSessionFilters.elm
  41. +9 −7 app/javascript/elm/src/LabelsInput.elm
  42. +596 −0 app/javascript/elm/src/Main.elm
  43. +0 −300 app/javascript/elm/src/MobileSessionsFilters.elm
  44. +18 −1 app/javascript/elm/src/Ports.elm
  45. +0 −191 app/javascript/elm/src/SessionsList.elm
  46. +12 −9 app/javascript/elm/src/TimeRange.elm
  47. +0 −37 app/javascript/elm/tests/FixedSessionsFiltersTests.elm
  48. +4 −4 app/javascript/elm/tests/LabelsInputTests.elm
  49. +198 −15 app/javascript/elm/tests/{MobileSessionsFiltersTests.elm → MainTests.elm}
  50. +0 −201 app/javascript/elm/tests/SessionsListTests.elm
  51. +2 −2 app/javascript/elm/tests/TimeRangeTests.elm
  52. +36 −32 app/javascript/packs/application.js
  53. +38 −0 app/javascript/packs/elm.js
  54. +5 −21 app/views/layouts/map.html.haml
  55. 0 app/views/maps/index.html.erb
  56. +0 −12 app/views/maps/show.html.erb
  57. +0 −85 app/views/yellow/index.html.erb
  58. +3 −3 config/routes.rb
  59. +1 −3 config/webpack/loaders/elm.js
  60. +1 −1 elm.json
  61. +0 −2 package.json
  62. +0 −52 public/partials/fixed_sessions_map.html
  63. +0 −9 public/partials/graph.html
  64. +0 −60 public/partials/heat_legend.html
  65. +0 −22 public/partials/left_hud.html
  66. +0 −32 public/partials/mobile_sessions_map.html
  67. +0 −13 public/partials/sessions_list.html
  68. +0 −23 spec/controllers/maps_controller_spec.rb
  69. +0 −8 yarn.lock
@@ -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.
@@ -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;
}
@@ -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

This file was deleted.

@@ -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';
@@ -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'

@@ -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;
@@ -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 })
@@ -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;
@@ -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"
)

@@ -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;
@@ -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;
@@ -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;
@@ -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"
)

@@ -1,6 +1,5 @@
import _ from 'underscore';
import { formatSessionForList } from '../values/session'
import { Elm } from '../../../elm/src/SessionsList.elm';

export const SessionsListCtrl = (
$scope,
@@ -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() {
@@ -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
@@ -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){
@@ -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);
};
@@ -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);
@@ -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.
You can’t perform that action at this time.