diff --git a/Server/app/resources/basic/BasicController.jl b/Server/app/resources/basic/BasicController.jl index 3642cda..308d47f 100644 --- a/Server/app/resources/basic/BasicController.jl +++ b/Server/app/resources/basic/BasicController.jl @@ -213,33 +213,7 @@ end function groups_add_post() data = jsonpayload() - insert_into_table("groups",data) + insert_into_table("groups_requests",data) end -#= -function compile_groups() - function table_to_json(name,t) - ar = [] - for df_row in eachrow(t) - - df_row = first(eachrow(df)) - id = :town - location = String[] - for id in [:country,:state,:town] - if !isempty(df_row[id]) - push!(location,df_row[id]) - end - end - df = select_from_table(["groups" => ["*"]]) - dict = Dict( - "location" => [location,[df_row[:latitude],df_row[:longitude]]], - "members" => df_row[:members], - "contact" => df_row[:contact] - ) - end - return ar - end - df = select_from_table(["groups" => ["*"]]) end -=# -end diff --git a/Server/app/svelte/public/js/groups.js b/Server/app/svelte/public/js/groups.js index 61c3611..1319310 100644 --- a/Server/app/svelte/public/js/groups.js +++ b/Server/app/svelte/public/js/groups.js @@ -1,3 +1,4 @@ +/* export let groups = [ { location: [["Bulgaria","Varna"],[43.21582161671174, 27.89896092161012]], @@ -85,17 +86,7 @@ export let groups = [ contact: ["https://discord.gg/Qk8KUk787z","DiscordInviteLink"] } ] - -export let groupsByCountry = {} -for (let g of groups) { - let country = g.location[0][0] - if (country in groupsByCountry) { - groupsByCountry[country].push(g) - } - else { - groupsByCountry[country] = [g] - } -} +*/ export let groupsMarkersLayer = L.layerGroup() let groupsMarkersLayerOut = L.layerGroup() @@ -116,13 +107,14 @@ export function translate(content, x) { function addMarkersToLayer(g,layer,content,locale) { let coordinates let text = ""+content["Group"]+"
" - for (let field in g) { + for (let field of ["location","members","contact"]) { + let fieldText = content[field] + ": " if (field=="contact") { - text += fieldText + "" + content[g.contact[1]] + "" + text += fieldText + "" + g.contact + "" } else if (field=="location") { - let location = g[field][0] + let location = [g.country,g.state,g.town].filter(x => x!=null && x!=undefined) let locationString if (locale=="en") { locationString = location.map(x => x).join(", ") @@ -131,7 +123,7 @@ function addMarkersToLayer(g,layer,content,locale) { locationString = location.map(x => translate(content, x)).join(", ") } text += fieldText + locationString + "
" - coordinates = g[field][1] + coordinates = [g.latitude,g.longitude] } else { text += fieldText + g[field] + "
" @@ -145,28 +137,29 @@ function addMarkersToLayer(g,layer,content,locale) { popupAnchor: [1, -34], shadowSize: [41, 41] }) + //console.log(text) let marker = L.marker(coordinates, {icon: markerIcon}) marker.addTo(layer).bindPopup(text) } -export function addMarkersGroups(map,content,locale) { +export function addMarkersGroups(groups,groupsByCountry,map,content,locale) { for (let g of groups) { addMarkersToLayer(g,groupsMarkersLayerIn,content,locale) } for (let gs of Object.values(groupsByCountry)) { if (gs.length==1) { let g = {...gs[0]} - g.location[0] = [g.location[0][0]] + g.country = [g.country] addMarkersToLayer(g,groupsMarkersLayerOut,content,locale) } else { - let locationName = [gs[0].location[0][0]] + let locationName = gs[0].country let locationCoordinates = [0,0] let members = 0 let contact = gs[0].contact for (let g of gs) { - locationCoordinates[0] += g.location[1][0] - locationCoordinates[1] += g.location[1][1] + locationCoordinates[0] += g.latitude + locationCoordinates[1] += g.longitude members += g.members if (g.contact[0]!=gs[0].contact[0]) { contact = contactGeneral @@ -175,13 +168,16 @@ export function addMarkersGroups(map,content,locale) { locationCoordinates[0] = locationCoordinates[0]/gs.length locationCoordinates[1] = locationCoordinates[1]/gs.length let gNew = { - location: [locationName,locationCoordinates], + country: locationName, + latitude: locationCoordinates[0], + longitude: locationCoordinates[1], members: members, contact: contact } addMarkersToLayer(gNew,groupsMarkersLayerOut,content,locale) } } + groupsMarkersLayerOut.addTo(groupsMarkersLayer) groupsMarkersLayer.addTo(map) map.on("zoomend", () => onZoomEnd(map)) diff --git a/Server/app/svelte/src/groups-add-component.svelte b/Server/app/svelte/src/groups-add-component.svelte index 0694b91..32d8b31 100644 --- a/Server/app/svelte/src/groups-add-component.svelte +++ b/Server/app/svelte/src/groups-add-component.svelte @@ -4,7 +4,7 @@ // Import statements import { onMount } from 'svelte' import { writable } from 'svelte/store'; - import { groupsByCountry, addMarkersGroups } from '/js/groups.js' + import { addMarkersGroups, translate } from '/js/groups.js' import { loadLocaleContent, getData, sendData } from "/js/libraries/serverTools.js" // Import components @@ -13,6 +13,30 @@ // Main code let loaded = writable(0) let content = writable({}) + let groups + let groupsByCountry + + let callback = (response) => { + groups = JSON.parse(response) + groupsByCountry = {} + for (let g of groups) { + let country = g.country + if (g.contact==null) { + g.contact = "https://discord.gg/Qk8KUk787z" + } + if (country in groupsByCountry) { + groupsByCountry[country].push(g) + } + else { + groupsByCountry[country] = [g] + } + } + loaded.update((val) => { + return val + 1 + }) + } + getData("/assets/groups.json",callback) + let confirmationMsg let addressInput @@ -76,7 +100,7 @@ function mapCallbackGroups(createMap,content,locale) { let map = createMap([22, 0],2) - addMarkersGroups(map,content,locale) + addMarkersGroups(groups,groupsByCountry,map,content,locale) userPin.addTo(map) map.on('click', function(event) { @@ -111,8 +135,7 @@ town: addressVec[2], latitude: userPinLat, longitude: userPinLng, - contact: contactInput.value, - members: 1 + contact: contactInput.value } if (data.state=="") { @@ -139,7 +162,7 @@ {#key $loaded} - {#if $loaded==2} + {#if $loaded==3}
diff --git a/Server/app/svelte/src/groups-component.svelte b/Server/app/svelte/src/groups-component.svelte index abc7d22..514ecb8 100644 --- a/Server/app/svelte/src/groups-component.svelte +++ b/Server/app/svelte/src/groups-component.svelte @@ -4,7 +4,7 @@ // Import statements import { onMount } from 'svelte' import { writable } from 'svelte/store'; - import { groupsByCountry, addMarkersGroups, translate } from '/js/groups.js' + import { addMarkersGroups, translate } from '/js/groups.js' import { loadLocaleContent, getData, sendData } from "/js/libraries/serverTools.js" // Import components @@ -13,21 +13,47 @@ // Main code let loaded = writable(0) let content = writable({}) + let groups + let groupsByCountry let locale = loadLocaleContent(content,"groups-component",loaded) loadLocaleContent(content,"countries",loaded) + let callback = (response) => { + groups = JSON.parse(response) + groupsByCountry = {} + for (let g of groups) { + let country = g.country + if (g.contact==null) { + g.contact = "https://discord.gg/Qk8KUk787z" + } + if (country in groupsByCountry) { + groupsByCountry[country].push(g) + } + else { + groupsByCountry[country] = [g] + } + } + loaded.update((val) => { + return val + 1 + }) + } + getData("/assets/groups.json",callback) + + + function mapCallbackGroups(createMap,content,locale) { let map = createMap([22, 0],2) - addMarkersGroups(map,content,locale) + addMarkersGroups(groups,groupsByCountry,map,content,locale) } function getCountry(x) { return locale=="en" ? x : translate($content,x) } - function getAddress(group) { - return group.location[0].map(x => locale=="en" ? x : translate($content,x)).join(", ") + function getAddress(g) { + let location = [g.country,g.state,g.town].filter(x => x!=null) + return location.map(x => locale=="en" ? x : translate($content,x)).join(", ") } onMount(() => { @@ -36,7 +62,7 @@ {#key $loaded} - {#if $loaded==2} + {#if $loaded==3}
@@ -53,7 +79,7 @@

{$content.location}: {getAddress(group)}

{$content.members}: {group.members}

-

{$content.contact}: {$content[group.contact[1]]}

+

{$content.contact}: {group.contact}

{/each}
diff --git a/Server/db/migrations/2022026611846566_create_table_groups_requests.jl b/Server/db/migrations/2022026611846566_create_table_groups_requests.jl new file mode 100644 index 0000000..b4e74a0 --- /dev/null +++ b/Server/db/migrations/2022026611846566_create_table_groups_requests.jl @@ -0,0 +1,32 @@ +module CreateTableGroupsRequests + +import SearchLight.Migrations: create_table, column, primary_key, add_index, drop_table + +include("../../lib/DatabaseSupport.jl") +using .DatabaseSupport + +function up() + create_table(:groups_requests) do + [ + primary_key() + column(:id_given, :integer) + column(:country, :string) + column(:state, :string) + column(:town, :string) + column(:contact, :string) + column(:latitude, :float) + column(:longitude, :float) + column(:verified, :bool) + column(:added, :bool) + ] + end + + set_default("groups_requests","verified",false) + set_default("groups_requests","added",false) +end + +function down() + drop_table(:groups) +end + +end \ No newline at end of file diff --git a/Server/lib/DatabaseSupport.jl b/Server/lib/DatabaseSupport.jl index b1395ae..ee30e3e 100644 --- a/Server/lib/DatabaseSupport.jl +++ b/Server/lib/DatabaseSupport.jl @@ -4,7 +4,7 @@ module DatabaseSupport using SearchLight, SearchLightPostgreSQL, LibPQ using DataFrames -export exist_in_table, insert_into_table, update_table, select_from_table, add_foreign_key +export exist_in_table, insert_into_table, update_table, select_from_table, add_foreign_key, set_default options = SearchLight.Configuration.read_db_connection_data("db/connection.yml") conn = SearchLight.connect(options) @@ -12,7 +12,7 @@ conn = SearchLight.connect(options) function format(x) if (x isa String) || (x isa Symbol) return string("'",x,"'") - elseif (isnothing(x)) + elseif (isnothing(x) || ismissing(x)) return "NULL" else return x @@ -33,7 +33,7 @@ end function update_table(table_name,dict_values; where_data=nothing) ns = collect(keys(dict_values)) vals_raw = values(dict_values) - vals = map(x -> x isa String ? string("'",x,"'") : x,vals_raw) + vals = map(x -> format(x),vals_raw) ns_vals = join(map((x,y) -> string(x, " = ",y),ns,vals),", ") query = "UPDATE $table_name SET $ns_vals" @@ -144,4 +144,11 @@ function add_foreign_key(table,name,table2,name2) SearchLight.query(query) end +function set_default(table,column,value) + query = """ + ALTER TABLE $table + ALTER COLUMN $column SET DEFAULT $value ;""" + SearchLight.query(query) +end + end diff --git a/Server/lib_ext/compile_database.jl b/Server/lib_ext/compile_database.jl new file mode 100644 index 0000000..5e85e61 --- /dev/null +++ b/Server/lib_ext/compile_database.jl @@ -0,0 +1,57 @@ + +using SearchLight, SearchLightPostgreSQL, LibPQ, JSON3 +using DataFrames +include("../lib/DatabaseSupport.jl") +using .DatabaseSupport + +function table_to_json(name,df) + ar = [] + for df_row in eachrow(df) + dict = Dict() + for id in names(df_row) + dict[id] = df_row[id] + end + push!(ar,dict) + end + open("public/assets/"*name*".json", "w") do io + JSON3.write(io, ar) + end +end + +function compile_groups() + df = select_from_table(["groups" => ["*"]]) + table_to_json("groups",df) +end + +function move_requests() + df_requests = select_from_table(["groups_requests" => ["*"]], where_data=["verified" => true, "added" => false]) + df = select_from_table(["groups" => ["*"]]) + latitudes = df.latitude + longitudes = df.longitude + for df_row in eachrow(df_requests) + ind_id_given = ismissing(df_row.id_given) ? nothing : findfirst(df_row.id_given.==df.id) + if (!isnothing(ind_id_given)) + id = df[ind_id_given,:id] + row_found = df[ind_id_given,Not(:id)] + dict = Dict(zip(names(row_found),values(row_found))) + dict["members"] += 1 + update_table("groups",dict, where_data=["id" => id]) + else + id = df_row.id + dict_update = Dict("added" => true) + update_table("groups_requests",dict_update, where_data=["id" => id]) + + df_row_to_add = df_row[Not(:id_given)] + df_row_to_add = df_row_to_add[Not(:verified)] + df_row_to_add = df_row_to_add[Not(:added)] + df_row_to_add = df_row_to_add[Not(:id)] + dict = Dict(zip(names(df_row_to_add),values(df_row_to_add))) + dict["members"] = 1 + insert_into_table("groups",dict) + end + end +end + + +move_requests() +compile_groups() diff --git a/Server/public/assets/groups.json b/Server/public/assets/groups.json new file mode 100644 index 0000000..837d187 --- /dev/null +++ b/Server/public/assets/groups.json @@ -0,0 +1 @@ +[{"town":"Atlanta","contact":null,"latitude":33.7243396617476,"longitude":-84.39697265625,"id":9,"members":1,"country":"United States","state":"Georgia"},{"town":null,"contact":null,"latitude":39.98855476000615,"longitude":-105.2105712890625,"id":10,"members":1,"country":"United States","state":"Colorado"},{"town":null,"contact":null,"latitude":28.27955105276024,"longitude":-81.47460937500001,"id":11,"members":1,"country":"United States","state":"Florida"},{"town":"Dublin","contact":null,"latitude":40.13360099478965,"longitude":-83.10607910156251,"id":12,"members":1,"country":"United States","state":"Ohio"},{"town":"Toronto","contact":null,"latitude":43.68959002213805,"longitude":-79.36523437500001,"id":13,"members":1,"country":"Canada","state":"Ontario"},{"town":"Halifax","contact":null,"latitude":44.64996307546047,"longitude":-63.60809326171876,"id":14,"members":1,"country":"Canada","state":"Nova Scotia"},{"town":null,"contact":null,"latitude":53.353612430518126,"longitude":-8.085937500000002,"id":15,"members":1,"country":"Ireland","state":null},{"town":"Cham","contact":null,"latitude":47.18444711300418,"longitude":8.461189270019533,"id":16,"members":1,"country":"Switzerland","state":"Zug"},{"town":"Wiesbaden","contact":null,"latitude":50.085975903187155,"longitude":8.240432739257814,"id":17,"members":1,"country":"Germany","state":"Hesse"},{"town":"Copenhagen","contact":null,"latitude":55.68832070332783,"longitude":12.568359375000002,"id":18,"members":1,"country":"Denmark","state":"Capital Region of Denmark"},{"town":"Kolding","contact":null,"latitude":55.5095568556412,"longitude":9.486694335937502,"id":19,"members":1,"country":"Denmark","state":null},{"town":"Municipal Unit of Moschato","contact":null,"latitude":37.950275539773436,"longitude":23.673992156982425,"id":20,"members":1,"country":"Greece","state":"Attica"},{"town":"Varna","contact":null,"latitude":43.18381722560103,"longitude":27.905273437500004,"id":21,"members":1,"country":"Bulgaria","state":null},{"town":"Riga","contact":null,"latitude":56.966939887376796,"longitude":24.142456054687504,"id":22,"members":1,"country":"Latvia","state":"Vidzeme"},{"town":"Kohtla-Järve linn","contact":null,"latitude":59.40196127188141,"longitude":27.28042602539063,"id":23,"members":1,"country":"Estonia","state":null},{"town":"Tallinn","contact":null,"latitude":59.39656672058008,"longitude":24.72610473655427,"id":24,"members":1,"country":"Estonia","state":null},{"town":"Chiang Mai","contact":null,"latitude":18.796128352413316,"longitude":98.98753015423392,"id":25,"members":1,"country":"Thailand","state":null}] \ No newline at end of file diff --git a/Server/public/js/components/groups-add-component.js b/Server/public/js/components/groups-add-component.js index 8ce69db..d366468 100644 --- a/Server/public/js/components/groups-add-component.js +++ b/Server/public/js/components/groups-add-component.js @@ -1 +1 @@ -import{S as t,i as n,a as e,b as o,s as i,e as r,n as a,d as s,c as l,o as m,w as p,f as c,g as u,h as d,j as g,k as h,l as f,q as b,r as w}from"./index-4348483d.js";import{w as y}from"./index-71440b21.js";import{addMarkersGroups as v}from"../../../../../../../../../js/groups.js";import{loadLocaleContent as x,getData as k,sendData as j}from"../../../../../../../../../js/libraries/serverTools.js";import"../../../../../../../../../js/components/map-component.js";function z(t){let n,e,i,r,a,l,m,p,y,v,x,k,j,L,z,S,C,T,H,M,A,N,O,q,E,D,I,R,U,$,G,J,P,V,Y;return{c(){n=c("div"),e=c("div"),i=c("h1"),i.textContent="Add a Group",r=u(),a=c("img"),m=u(),p=c("p"),p.textContent="If there are no groups in your town with whom you can organize then do the following:",y=u(),v=c("ol"),v.innerHTML="
  • Click on the map to show us where you are located;
  • \n
  • Add a way to contact you or leave blank for a pin to point to our discord;
  • \n
  • Press "Submit" to add yourself to our map;
  • \n
  • Verify yourself by having a chat with us at our Discord server to show on the map;
  • ",x=u(),k=c("div"),j=c("label"),j.textContent="Location:",L=u(),z=c("div"),S=c("input"),C=u(),T=c("div"),H=u(),M=c("div"),A=c("label"),A.textContent="Contact:",N=u(),O=c("div"),q=c("input"),E=u(),D=c("div"),I=u(),R=c("button"),R.textContent="Submit",U=u(),$=c("p"),G=u(),J=c("map-component"),d(a,"id","groups-img"),g(a.src,l="/img/common/groups.svg")||d(a,"src","/img/common/groups.svg"),d(a,"alt","groups"),d(p,"class","description"),d(j,"for","address-input"),d(S,"id","address-input"),d(S,"type","text"),S.readOnly=!0,d(T,"class","ghost-input"),d(z,"class","input-wrapper"),d(k,"id","address-input-wrapper"),d(k,"class","input-label-wrapper"),d(A,"for","contact-input"),d(q,"id","contact-input"),d(q,"type","text"),d(D,"class","ghost-input"),d(O,"class","input-wrapper"),d(M,"class","input-label-wrapper"),d(R,"id","submit-button"),d($,"id","confirmation-msg"),h(J,"id","map"),h(J,"callback",P=t[15]),d(e,"id","text-container"),d(n,"id","container")},m(s,l){o(s,n,l),f(n,e),f(e,i),f(e,r),f(e,a),f(e,m),f(e,p),f(e,y),f(e,v),f(e,x),f(e,k),f(k,j),f(k,L),f(k,z),f(z,S),t[10](S),f(z,C),f(z,T),f(e,H),f(e,M),f(M,A),f(M,N),f(M,O),f(O,q),t[12](q),f(O,E),f(O,D),f(e,I),f(e,R),f(e,U),f(e,$),t[14]($),f(e,G),f(e,J),V||(Y=[b(S,"input",t[11]),b(q,"input",t[13]),b(R,"click",t[9])],V=!0)},p(t,n){16&n&&P!==(P=t[15])&&h(J,"callback",P)},d(e){e&&s(n),t[10](null),t[12](null),t[14](null),V=!1,w(Y)}}}function S(t){let n,e=2==t[3]&&z(t);return{c(){e&&e.c(),n=r()},m(t,i){e&&e.m(t,i),o(t,n,i)},p(t,o){2==t[3]?e?e.p(t,o):(e=z(t),e.c(),e.m(n.parentNode,n)):e&&(e.d(1),e=null)},d(t){e&&e.d(t),t&&s(n)}}}function C(t){let n,e=t[3],l=S(t);return{c(){l.c(),n=r(),this.c=a},m(t,e){l.m(t,e),o(t,n,e)},p(t,[o]){8&o&&i(e,e=t[3])?(l.d(1),l=S(t),l.c(),l.m(n.parentNode,n)):l.p(t,o)},i:a,o:a,d(t){t&&s(n),l.d(t)}}}function T(t){t.nextElementSibling.innerHTML=t.value}function H(t,n,e){let o,i,r=y(0);l(t,r,(t=>e(3,o=t)));let a,s,c,u,d=y({});l(t,d,(t=>e(4,i=t)));let g=0,h=0,f=function(t,n){let e=new L.Icon({iconUrl:"/img/common/markers/marker-black.png",shadowUrl:"https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png",iconSize:[25,41],iconAnchor:[12,41],popupAnchor:[1,-34],shadowSize:[41,41]});return L.marker([t,n],{icon:e})}(0,0);f.setOpacity(0);let b=x(d,"groups-component",r);function w(t,n,o){let i=t([22,0],2);v(i,n,o),f.addTo(i),i.on("click",(function(t){let n=t.latlng.lat,o=t.latlng.lng;g=n,h=o,function(t,n,e){let o=L.latLng(n,e);t.setLatLng(o)}(f,n,o),f.setOpacity(1),k(`https://nominatim.openstreetmap.org/reverse?lat=${n}&lon=${o}&format=jsonv2`,(t=>{let n=(t=JSON.parse(t)).address,o=n.city||n.town||n.village||n.hamlet,i=n.state,r=n.country,a=r;null!=i?a+=", "+i:i="",null!=o?a+=", "+o:o="",e(1,s.value=a,s),T(s),u=[r,i,o]}))}))}function z(t){!1!==t?(e(0,a.innerHTML="You have been added to our database! Now go to our Discord to verify yourself.",a),e(0,a.style.color="green",a)):(e(0,a.innerHTML="Something went wrong.",a),e(0,a.style.color="red",a))}x(d,"countries",r),m((()=>{}));return[a,s,c,o,i,r,d,b,w,function(){if(null!=u){let t={country:u[0],state:u[1],town:u[2],latitude:g,longitude:h,contact:c.value,members:1};""==t.state&&(t.state=null),""==t.town&&(t.town=null),""==t.contact&&(t.contact=null),j("/"+b+"/groups-add-post/",t,z)}},function(t){p[t?"unshift":"push"]((()=>{s=t,e(1,s)}))},()=>T(s),function(t){p[t?"unshift":"push"]((()=>{c=t,e(2,c)}))},()=>T(c),function(t){p[t?"unshift":"push"]((()=>{a=t,e(0,a)}))},t=>w(t,i,b)]}class M extends t{constructor(t){super(),this.shadowRoot.innerHTML="",n(this,{target:this.shadowRoot,props:e(this.attributes),customElement:!0},H,C,i,{},null),t&&t.target&&o(t.target,this,t.anchor)}}customElements.define("groups-add-component",M);export{M as default}; +import{S as t,i as n,a as e,b as o,s as i,e as r,n as a,d as s,c as l,o as m,w as c,f as p,g as u,h as d,j as g,k as h,l as f,q as b,r as w}from"./index-4348483d.js";import{w as y}from"./index-71440b21.js";import{addMarkersGroups as v}from"../../../../../../../../../js/groups.js";import{getData as x,loadLocaleContent as k,sendData as j}from"../../../../../../../../../js/libraries/serverTools.js";import"../../../../../../../../../js/components/map-component.js";function z(t){let n,e,i,r,a,l,m,c,y,v,x,k,j,L,z,S,C,T,H,M,N,O,A,q,E,U,D,I,J,R,$,G,K,P,Q;return{c(){n=p("div"),e=p("div"),i=p("h1"),i.textContent="Add a Group",r=u(),a=p("img"),m=u(),c=p("p"),c.textContent="If there are no groups in your town with whom you can organize then do the following:",y=u(),v=p("ol"),v.innerHTML="
  • Click on the map to show us where you are located;
  • \n
  • Add a way to contact you or leave blank for a pin to point to our discord;
  • \n
  • Press "Submit" to add yourself to our map;
  • \n
  • Verify yourself by having a chat with us at our Discord server to show on the map;
  • ",x=u(),k=p("div"),j=p("label"),j.textContent="Location:",L=u(),z=p("div"),S=p("input"),C=u(),T=p("div"),H=u(),M=p("div"),N=p("label"),N.textContent="Contact:",O=u(),A=p("div"),q=p("input"),E=u(),U=p("div"),D=u(),I=p("button"),I.textContent="Submit",J=u(),R=p("p"),$=u(),G=p("map-component"),d(a,"id","groups-img"),g(a.src,l="/img/common/groups.svg")||d(a,"src","/img/common/groups.svg"),d(a,"alt","groups"),d(c,"class","description"),d(j,"for","address-input"),d(S,"id","address-input"),d(S,"type","text"),S.readOnly=!0,d(T,"class","ghost-input"),d(z,"class","input-wrapper"),d(k,"id","address-input-wrapper"),d(k,"class","input-label-wrapper"),d(N,"for","contact-input"),d(q,"id","contact-input"),d(q,"type","text"),d(U,"class","ghost-input"),d(A,"class","input-wrapper"),d(M,"class","input-label-wrapper"),d(I,"id","submit-button"),d(R,"id","confirmation-msg"),h(G,"id","map"),h(G,"callback",K=t[15]),d(e,"id","text-container"),d(n,"id","container")},m(s,l){o(s,n,l),f(n,e),f(e,i),f(e,r),f(e,a),f(e,m),f(e,c),f(e,y),f(e,v),f(e,x),f(e,k),f(k,j),f(k,L),f(k,z),f(z,S),t[10](S),f(z,C),f(z,T),f(e,H),f(e,M),f(M,N),f(M,O),f(M,A),f(A,q),t[12](q),f(A,E),f(A,U),f(e,D),f(e,I),f(e,J),f(e,R),t[14](R),f(e,$),f(e,G),P||(Q=[b(S,"input",t[11]),b(q,"input",t[13]),b(I,"click",t[9])],P=!0)},p(t,n){16&n&&K!==(K=t[15])&&h(G,"callback",K)},d(e){e&&s(n),t[10](null),t[12](null),t[14](null),P=!1,w(Q)}}}function S(t){let n,e=3==t[3]&&z(t);return{c(){e&&e.c(),n=r()},m(t,i){e&&e.m(t,i),o(t,n,i)},p(t,o){3==t[3]?e?e.p(t,o):(e=z(t),e.c(),e.m(n.parentNode,n)):e&&(e.d(1),e=null)},d(t){e&&e.d(t),t&&s(n)}}}function C(t){let n,e=t[3],l=S(t);return{c(){l.c(),n=r(),this.c=a},m(t,e){l.m(t,e),o(t,n,e)},p(t,[o]){8&o&&i(e,e=t[3])?(l.d(1),l=S(t),l.c(),l.m(n.parentNode,n)):l.p(t,o)},i:a,o:a,d(t){t&&s(n),l.d(t)}}}function T(t){t.nextElementSibling.innerHTML=t.value}function H(t,n,e){let o,i,r=y(0);l(t,r,(t=>e(3,o=t)));let a,s,p=y({});l(t,p,(t=>e(4,i=t)));let u,d,g,h;x("/assets/groups.json",(t=>{a=JSON.parse(t),s={};for(let t of a){let n=t.country;null==t.contact&&(t.contact="https://discord.gg/Qk8KUk787z"),n in s?s[n].push(t):s[n]=[t]}r.update((t=>t+1))}));let f=0,b=0,w=function(t,n){let e=new L.Icon({iconUrl:"/img/common/markers/marker-black.png",shadowUrl:"https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png",iconSize:[25,41],iconAnchor:[12,41],popupAnchor:[1,-34],shadowSize:[41,41]});return L.marker([t,n],{icon:e})}(0,0);w.setOpacity(0);let z=k(p,"groups-component",r);function S(t,n,o){let i=t([22,0],2);v(a,s,i,n,o),w.addTo(i),i.on("click",(function(t){let n=t.latlng.lat,o=t.latlng.lng;f=n,b=o,function(t,n,e){let o=L.latLng(n,e);t.setLatLng(o)}(w,n,o),w.setOpacity(1),x(`https://nominatim.openstreetmap.org/reverse?lat=${n}&lon=${o}&format=jsonv2`,(t=>{let n=(t=JSON.parse(t)).address,o=n.city||n.town||n.village||n.hamlet,i=n.state,r=n.country,a=r;null!=i?a+=", "+i:i="",null!=o?a+=", "+o:o="",e(1,d.value=a,d),T(d),h=[r,i,o]}))}))}function C(t){!1!==t?(e(0,u.innerHTML="You have been added to our database! Now go to our Discord to verify yourself.",u),e(0,u.style.color="green",u)):(e(0,u.innerHTML="Something went wrong.",u),e(0,u.style.color="red",u))}k(p,"countries",r),m((()=>{}));return[u,d,g,o,i,r,p,z,S,function(){if(null!=h){let t={country:h[0],state:h[1],town:h[2],latitude:f,longitude:b,contact:g.value};""==t.state&&(t.state=null),""==t.town&&(t.town=null),""==t.contact&&(t.contact=null),j("/"+z+"/groups-add-post/",t,C)}},function(t){c[t?"unshift":"push"]((()=>{d=t,e(1,d)}))},()=>T(d),function(t){c[t?"unshift":"push"]((()=>{g=t,e(2,g)}))},()=>T(g),function(t){c[t?"unshift":"push"]((()=>{u=t,e(0,u)}))},t=>S(t,i,z)]}class M extends t{constructor(t){super(),this.shadowRoot.innerHTML="",n(this,{target:this.shadowRoot,props:e(this.attributes),customElement:!0},H,C,i,{},null),t&&t.target&&o(t.target,this,t.anchor)}}customElements.define("groups-add-component",M);export{M as default}; diff --git a/Server/public/js/components/groups-component.js b/Server/public/js/components/groups-component.js index e8af626..dc4b9cd 100644 --- a/Server/public/js/components/groups-component.js +++ b/Server/public/js/components/groups-component.js @@ -1 +1 @@ -import{S as t,i as o,a as n,b as e,s as r,e as i,n as m,d as a,c as s,o as c,f as l,t as p,g,h as u,j as d,k as h,l as f,m as b,p as j}from"./index-4348483d.js";import{w as x}from"./index-71440b21.js";import{addMarkersGroups as v,translate as w,groupsByCountry as y}from"../../../../../../../../../js/groups.js";import{loadLocaleContent as k}from"../../../../../../../../../js/libraries/serverTools.js";import"../../../../../../../../../js/components/map-component.js";function z(t,o,n){const e=t.slice();return e[9]=o[n][0],e[10]=o[n][1],e}function D(t,o,n){const e=t.slice();return e[13]=o[n],e}function E(t){let o,n,r,i,m,s,c,x,v,w,k,D,E,N,R,T,A,C,H,L,M=t[0].groups+"",S=t[0].p1+"",_=t[0].subheading1+"",q=t[0]["map-prompt"]+"",B=Object.entries(y),F=[];for(let o=0;on(1,r=t)));let m=x({});s(t,m,(t=>n(0,e=t)));let a=k(m,"groups-component",i);function l(t,o,n){let e=t([22,0],2);v(e,o,n)}k(m,"countries",i),c((()=>{}));return[e,r,i,m,a,l,function(t){return"en"==a?t:w(e,t)},function(t){return t.location[0].map((t=>"en"==a?t:w(e,t))).join(", ")},t=>l(t,e,a)]}class C extends t{constructor(t){super(),this.shadowRoot.innerHTML="",o(this,{target:this.shadowRoot,props:n(this.attributes),customElement:!0},A,T,r,{},null),t&&t.target&&e(t.target,this,t.anchor)}}customElements.define("groups-component",C);export{C as default}; +import{S as t,i as o,a as n,b as e,s as r,e as s,n as a,d as i,c as m,o as c,f as l,t as p,g as u,h as g,j as d,k as f,l as h,m as b,p as j}from"./index-4348483d.js";import{w as x}from"./index-71440b21.js";import{addMarkersGroups as y,translate as v}from"../../../../../../../../../js/groups.js";import{loadLocaleContent as w,getData as k}from"../../../../../../../../../js/libraries/serverTools.js";import"../../../../../../../../../js/components/map-component.js";function z(t,o,n){const e=t.slice();return e[12]=o[n][0],e[3]=o[n][1],e}function N(t,o,n){const e=t.slice();return e[15]=o[n],e}function O(t){let o,n,r,s,a,m,c,x,y,v,w,k,N,O,D,R,S,T,A,C,H=t[1].groups+"",J=t[1].p1+"",K=t[1].subheading1+"",L=t[1]["map-prompt"]+"",M=Object.entries(t[0]),Q=[];for(let o=0;on(2,r=t)));let a,i,l=x({});m(t,l,(t=>n(1,e=t)));let p=w(l,"groups-component",s);w(l,"countries",s);function u(t,o,n){let e=t([22,0],2);y(a,i,e,o,n)}k("/assets/groups.json",(t=>{n(3,a=JSON.parse(t)),n(0,i={});for(let t of a){let o=t.country;null==t.contact&&(t.contact="https://discord.gg/Qk8KUk787z"),o in i?i[o].push(t):n(0,i[o]=[t],i)}s.update((t=>t+1))})),c((()=>{}));return[i,e,r,a,s,l,p,u,function(t){return"en"==p?t:v(e,t)},function(t){return[t.country,t.state,t.town].filter((t=>null!=t)).map((t=>"en"==p?t:v(e,t))).join(", ")},t=>u(t,e,p)]}class A extends t{constructor(t){super(),this.shadowRoot.innerHTML="",o(this,{target:this.shadowRoot,props:n(this.attributes),customElement:!0},T,S,r,{},null),t&&t.target&&e(t.target,this,t.anchor)}}customElements.define("groups-component",A);export{A as default}; diff --git a/Server/public/js/groups.js b/Server/public/js/groups.js index 61c3611..1319310 100644 --- a/Server/public/js/groups.js +++ b/Server/public/js/groups.js @@ -1,3 +1,4 @@ +/* export let groups = [ { location: [["Bulgaria","Varna"],[43.21582161671174, 27.89896092161012]], @@ -85,17 +86,7 @@ export let groups = [ contact: ["https://discord.gg/Qk8KUk787z","DiscordInviteLink"] } ] - -export let groupsByCountry = {} -for (let g of groups) { - let country = g.location[0][0] - if (country in groupsByCountry) { - groupsByCountry[country].push(g) - } - else { - groupsByCountry[country] = [g] - } -} +*/ export let groupsMarkersLayer = L.layerGroup() let groupsMarkersLayerOut = L.layerGroup() @@ -116,13 +107,14 @@ export function translate(content, x) { function addMarkersToLayer(g,layer,content,locale) { let coordinates let text = ""+content["Group"]+"
    " - for (let field in g) { + for (let field of ["location","members","contact"]) { + let fieldText = content[field] + ": " if (field=="contact") { - text += fieldText + "" + content[g.contact[1]] + "" + text += fieldText + "" + g.contact + "" } else if (field=="location") { - let location = g[field][0] + let location = [g.country,g.state,g.town].filter(x => x!=null && x!=undefined) let locationString if (locale=="en") { locationString = location.map(x => x).join(", ") @@ -131,7 +123,7 @@ function addMarkersToLayer(g,layer,content,locale) { locationString = location.map(x => translate(content, x)).join(", ") } text += fieldText + locationString + "
    " - coordinates = g[field][1] + coordinates = [g.latitude,g.longitude] } else { text += fieldText + g[field] + "
    " @@ -145,28 +137,29 @@ function addMarkersToLayer(g,layer,content,locale) { popupAnchor: [1, -34], shadowSize: [41, 41] }) + //console.log(text) let marker = L.marker(coordinates, {icon: markerIcon}) marker.addTo(layer).bindPopup(text) } -export function addMarkersGroups(map,content,locale) { +export function addMarkersGroups(groups,groupsByCountry,map,content,locale) { for (let g of groups) { addMarkersToLayer(g,groupsMarkersLayerIn,content,locale) } for (let gs of Object.values(groupsByCountry)) { if (gs.length==1) { let g = {...gs[0]} - g.location[0] = [g.location[0][0]] + g.country = [g.country] addMarkersToLayer(g,groupsMarkersLayerOut,content,locale) } else { - let locationName = [gs[0].location[0][0]] + let locationName = gs[0].country let locationCoordinates = [0,0] let members = 0 let contact = gs[0].contact for (let g of gs) { - locationCoordinates[0] += g.location[1][0] - locationCoordinates[1] += g.location[1][1] + locationCoordinates[0] += g.latitude + locationCoordinates[1] += g.longitude members += g.members if (g.contact[0]!=gs[0].contact[0]) { contact = contactGeneral @@ -175,13 +168,16 @@ export function addMarkersGroups(map,content,locale) { locationCoordinates[0] = locationCoordinates[0]/gs.length locationCoordinates[1] = locationCoordinates[1]/gs.length let gNew = { - location: [locationName,locationCoordinates], + country: locationName, + latitude: locationCoordinates[0], + longitude: locationCoordinates[1], members: members, contact: contact } addMarkersToLayer(gNew,groupsMarkersLayerOut,content,locale) } } + groupsMarkersLayerOut.addTo(groupsMarkersLayer) groupsMarkersLayer.addTo(map) map.on("zoomend", () => onZoomEnd(map))