Skip to content

Commit

Permalink
fix te_fenua v1
Browse files Browse the repository at this point in the history
  • Loading branch information
maatinito committed Nov 6, 2023
1 parent 8d7668c commit b157e5c
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 1,006 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// = require_tree .
// = require ol
10 changes: 9 additions & 1 deletion app/assets/stylesheets/te_fenua.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// MES CONTRROLES

.ol-control-add {
left: 0.5em;
top: 5em;
Expand All @@ -18,6 +20,8 @@

.te-fenua {
position: relative;
width: 100%;
height: 500px;
}

.te-fenua-header {
Expand All @@ -28,12 +32,16 @@
background-color: rgba(0, 60, 136, 0.7);
border-radius: 5px;
left: 4em;
padding: 2px 2px 2px 2px;
padding: 5px 5px 5px 5px;
position: absolute;
right: 4em;
top: 0.4em;
z-index: 20;

input {
padding: 10px 10px 10px 10px;
width: 100%;
}
}

.te-fenua-help {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.te-fenua.edit{ class: "te-fenua-#{@form.index}", data: { entry: @champ.entry, marker: image_url('marker-icon.png') } }
.place
%input{ data: { te_fenua_place: true, autocomplete: 'te_fenua' }, placeholder: 'Hopital Raiatea, Eglise Faaone, K210 Pirae', 'aria-label': 'Adresse' }
-# .place
-# %input{ data: { te_fenua_place: true, autocomplete: 'te_fenua' }, placeholder: 'Hopital Raiatea, Eglise Faaone, K210 Pirae', 'aria-label': 'Adresse' }
.te-fenua-help.add
%p
Pour ajouter une zone.
Expand Down
42 changes: 21 additions & 21 deletions app/javascript/new_design/champs/te_fenua.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
createBatimentLayer,
createDefaultMap,
createManualZoneLayer,
createMarkerFeature,
// createMarkerFeature,
createMarkerLayer,
createParcelleLayer,
createTeFenuaLayer,
Expand All @@ -15,7 +15,7 @@ import Select from 'ol/interaction/Select.js';
import { GeoJSON } from 'ol/format';
import Geolocation from 'ol/Geolocation';
import Control from 'ol/control/Control';
import { delegate } from '../../shared/utils';
// import { delegate } from '../../shared/utils';
import {
createEmpty as olCreateEmpty,
extend as olExtend,
Expand All @@ -41,28 +41,28 @@ async function initialize() {
}
}

delegate('autocomplete:select', '[data-te-fenua-place]', (event) => {
let map = getMapFromAddress(event.target);
if (map) {
if (event.detail.extent) fitExtent(map, event.detail.extent);
else if (event.detail.point) moveMapTo(map, event.detail.point);
if (event.detail.point) {
const marker = createMarkerFeature(event.detail.point);
map.markerLayer.getSource().addFeature(marker);
}
}
});
// delegate('change', '[data-te-fenua-place]', (event) => {
// let map = getMapFromAddress(event.target);
// if (map) {
// if (event.detail.extent) fitExtent(map, event.detail.extent);
// else if (event.detail.point) moveMapTo(map, event.detail.point);
// if (event.detail.point) {
// const marker = createMarkerFeature(event.detail.point);
// map.markerLayer.getSource().addFeature(marker);
// }
// }
// });
}

function getInputFromMap(mapElement) {
return mapElement.parentElement.querySelector('input.features');
}

function getMapFromAddress(element) {
element = element.closest('.te-fenua');
return MAPS.get(element);
}

// function getMapFromAddress(element) {
// element = element.closest('.te-fenua');
// return MAPS.get(element);
// }
//
// We load leaflet dynamically, ramda and freedraw and assign them to globals.
// Latest freedraw version build needs globals.
// async function loadOpenLayers(editable) {
Expand Down Expand Up @@ -151,9 +151,9 @@ function centerMap(map) {
else fitExtent(map, extent);
}

function moveMapTo(map, point) {
map.getView().animate({ center: point });
}
// function moveMapTo(map, point) {
// map.getView().animate({ center: point });
// }

function fitExtent(map, extent) {
let view = map.getView();
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/new_design/champs/te_fenua_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function createParcellePolygonStyle() {
function getFeatureInfo(coordinate, resolution, projection, params) {
const url = new TileWMS({
url: 'https://www.tefenua.gov.pf/api/wms'
}).getGetFeatureInfoUrl(coordinate, resolution, projection, params);
}).getFeatureInfoUrl(coordinate, resolution, projection, params);
return fetch(url).then((result) => {
return result.json();
});
Expand Down
4 changes: 2 additions & 2 deletions app/lib/api_te_fenua/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def features
def get_features
response = self.class.search(@address)
result = JSON.parse(response, symbolize_names: true)
result[:content]
result[:content][:hits][:hits]
rescue RestClient::Exception, JSON::ParserError, TypeError
@blank_return
end
Expand All @@ -36,7 +36,7 @@ def self.search(search)
search_url = [API_TE_FENUA_URL, "recherche"].join("/")
RestClient::Request.execute(method: :get,
url: search_url,
timeout: 8,
timeout: 68,
headers: {
params: {
# mandatory but unused parameters
Expand Down
2 changes: 1 addition & 1 deletion app/models/types_de_champ/te_fenua_type_de_champ.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class TypesDeChamp::TeFenuaTypeDeChamp < TypesDeChamp::TypeDeChampBase
LAYERS = [:parcelles, :batiments, :zones_manuelles]
LAYERS = [:parcelles, :zones_manuelles] # , :batiments
end
1 change: 1 addition & 0 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Rails.application.config.assets.paths << Rails.root.join('node_modules', 'mapbox-gl', 'dist')
Rails.application.config.assets.paths << Rails.root.join('node_modules', '@reach', 'combobox')
Rails.application.config.assets.paths << Rails.root.join('node_modules', '@mapbox', 'mapbox-gl-draw', 'dist')
Rails.application.config.assets.paths << Rails.root.join('node_modules', 'ol')

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"is-hotkey": "^0.2.0",
"maplibre-gl": "^1.15.2",
"match-sorter": "^6.2.0",
"ol": "^5.3.3",
"ol": "^8.1.0",
"patch-package": "^7.0.0",
"react": "^18.2.0",
"react-coordinate-input": "^1.0.0",
Expand Down
56 changes: 56 additions & 0 deletions spec/fixtures/cassettes/api_te_fenua_with_results.yml

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions spec/fixtures/cassettes/api_te_fenua_without_result.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 8 additions & 20 deletions spec/lib/api_te_fenua/place_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,29 @@
describe APITeFenua::PlaceAdapter do
describe '#suggestions' do
let(:request) { 'Snack' }
let(:response) { File.open('spec/fixtures/files/api_te_fenua/results.json') }
let(:status) { 200 }

subject { described_class.new(request).suggestions }

before do
stub_request(:get, API_TE_FENUA_URL + "/recherche?d=0&id=&q=#{request}&sid=reqId&x=0&y=0")
.to_return(status: status, body: response, headers: {})
end

context 'when address return a list of places' do
let(:first_result) { { label: 'Snack - Moerai - Rurutu', point: [-151.336697436533, -22.4556400061971], extent: [-151.336792831641, -22.4557661428341, -151.336601293606, -22.4555065461003] } }
context 'when address return a list of places', vcr: "api_te_fenua_with_results" do
let(:first_result) { { extent: [-149.52659305755, -17.524524300323, -149.526381601545, -17.5243388893143], :label => "Snack - Arue - Tahiti", :point => [-149.52648802799, -17.5244329728184]} }
it { expect(subject.size).to eq 10 }
it { is_expected.to be_an_instance_of Array }
it { expect(subject[0]).to eq first_result }
end

context 'when address return an empty list' do
let(:response) { File.open('spec/fixtures/files/api_te_fenua/no_results.json') }
context 'when address return an empty list', vcr: "api_te_fenua_without_result" do
let(:request) { '####' }

it { expect(subject.size).to eq 0 }
it { is_expected.to be_an_instance_of Array }
end

context 'when BAN is unavailable' do
let(:status) { 503 }
let(:response) { '' }

it { expect(subject.size).to eq 0 }
it { is_expected.to be_an_instance_of Array }
end

context 'when request is empty' do
let(:response) { 'Missing query' }
let(:request) { '' }
before do
stub_request(:get, API_TE_FENUA_URL + "/recherche?d=0&id=&q=#{request}&sid=reqId&x=0&y=0")
.to_return(status: 503, body: '', headers: {})
end

it { expect(subject.size).to eq 0 }
it { is_expected.to be_an_instance_of Array }
Expand Down
Loading

0 comments on commit b157e5c

Please sign in to comment.