From e39b57871fe4e61339f2522e42d49ffb833f4ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kocy=C5=82a?= Date: Tue, 3 Dec 2024 13:09:14 +0100 Subject: [PATCH] dc clusters --- app/assets/stylesheets/application.scss | 30 +-- app/assets/stylesheets/data_center_map.scss | 44 +++++ .../api/v1/data_centers_controller.rb | 11 +- .../packs/data_centers/map_component.js | 2 + .../packs/data_centers/map_component.vue | 173 +++++++++++++++--- app/javascript/packs/stake_accounts/index.js | 1 + package.json | 1 + yarn.lock | 20 ++ 8 files changed, 226 insertions(+), 56 deletions(-) create mode 100644 app/assets/stylesheets/data_center_map.scss diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 63b7e6271..72b0b5683 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -30,6 +30,7 @@ @import "carousels"; @import "map"; @import "modals"; +@import "data_center_map"; html { overflow-x: hidden; @@ -50,35 +51,6 @@ body { } } -#map { - height: 600px; /* The height is 400 pixels */ - width: 100%; /* The width is the width of the web page */ -} - -#floating-panel { - position: absolute; - top: 10px; - left: 25%; - z-index: 5; - background-color: #fff; - padding: 5px; - border: 1px solid #999; - text-align: center; - font-family: "Roboto", "sans-serif"; - line-height: 30px; - padding-left: 10px; -} - -#floating-panel { - background-color: #fff; - border: 1px solid #999; - left: 25%; - padding: 5px; - position: absolute; - top: 10px; - z-index: 5; -} - .background-color { position: fixed; z-index: -2; diff --git a/app/assets/stylesheets/data_center_map.scss b/app/assets/stylesheets/data_center_map.scss new file mode 100644 index 000000000..493965404 --- /dev/null +++ b/app/assets/stylesheets/data_center_map.scss @@ -0,0 +1,44 @@ +#map { + height: 600px; /* The height is 400 pixels */ + width: 100%; /* The width is the width of the web page */ + border-radius: 25px; +} + +.data-center { + align-items: center; + background-color: #17132a; + border-radius: 50%; + color: #dedede; + display: flex; + font-size: 14px; + gap: 5px; + height: 23px; + justify-content: center; + padding: 4px; + position: relative; + position: relative; + transition: all 0.3s ease-out; + width: 23px; + + .data-center-details { + display: none; + flex-direction: column; + flex: 1; + } + + &.highlight { + // background-color: #FFFFFF; + border-radius: 8px; + box-shadow: 10px 10px 5px rgba(0, 0, 0, 0.2); + height: auto; + padding: 8px 15px; + width: 230px; + + .data-center-details { + padding-left: 10px; + display: block; + flex-direction: column; + flex: 1; + } + } + } diff --git a/app/controllers/api/v1/data_centers_controller.rb b/app/controllers/api/v1/data_centers_controller.rb index 34ed9a649..6aab0d3b6 100644 --- a/app/controllers/api/v1/data_centers_controller.rb +++ b/app/controllers/api/v1/data_centers_controller.rb @@ -65,8 +65,13 @@ def index_with_nodes end def index_for_map - data_centers = DataCenter.joins(:data_center_stats) + data_centers = DataCenter.select(:traits_organization, :data_center_key, :location_latitude, :location_longitude, :active_validators_count, :active_validators_stake, :traits_autonomous_system_number) + .joins(:data_center_stats) + .where("data_center_stats.network = ?", map_params[:network]) .where.not(data_center_key: "0--Unknown") + # if map_params[:asn_search].present? + # data_centers = data_centers.where("data_centers.traits_autonomous_system_number = ?", map_params[:asn_search]) + # end render json: { data_centers: data_centers }, status: :ok @@ -98,6 +103,10 @@ def data_center_stats def dc_params params.permit(:network, :show_gossip_nodes) end + + def map_params + params.permit(:network, :asn_search) + end end end end diff --git a/app/javascript/packs/data_centers/map_component.js b/app/javascript/packs/data_centers/map_component.js index d285ed5fa..b8e78c64b 100644 --- a/app/javascript/packs/data_centers/map_component.js +++ b/app/javascript/packs/data_centers/map_component.js @@ -1,12 +1,14 @@ import Vue from 'vue/dist/vue.esm' import TurbolinksAdapter from 'vue-turbolinks'; import MapComponent from './map_component.vue'; +import store from "../stores/main_store.js"; Vue.use(TurbolinksAdapter); document.addEventListener('turbolinks:load', () => { new Vue({ el: '#data-center-map-component', + store, render(createElement) { return createElement(MapComponent) } diff --git a/app/javascript/packs/data_centers/map_component.vue b/app/javascript/packs/data_centers/map_component.vue index 97bed280d..489376da2 100644 --- a/app/javascript/packs/data_centers/map_component.vue +++ b/app/javascript/packs/data_centers/map_component.vue @@ -1,18 +1,19 @@