Add new tilesets viewer static page (#16232)

pull/16242/head
Víctor Velarde 4 years ago committed by GitHub
parent 343a4a16c6
commit 68aa129bef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -58,6 +58,7 @@ Vagrantfile
.grunt/*
vendor/assets/javascripts/cartodb.*
vendor/assets/stylesheets/cartodb.*
config/unicorn.conf.rb
# cartodb.css is generated by update_cdb make task and is
# used in cartodb/cartodb/app/views/layouts/application.html.erb
!vendor/assets/stylesheets/cartodb.css

@ -39,6 +39,7 @@ sudo make install
- Migrate spec/models/carto to the new CI [#16228](https://github.com/CartoDB/cartodb/pull/16228)
- Add OAuth BigQuery connection [#16218](https://github.com/CartoDB/cartodb/pull/16218)
- Remove Data Observatory v1 [#16207](https://github.com/CartoDB/cartodb/pull/16207)
- Add new static page for tilesets viewer [#16232](https://github.com/CartoDB/cartodb/pull/16232)
### Bug fixes / enhancements

@ -0,0 +1,7 @@
class Admin::TilesetsViewerController < ApplicationController
protect_from_forgery except: :index
def index
render(file: "public/static/tilesets_viewer/index.html", layout: false)
end
end

@ -95,6 +95,7 @@ module CartoDB
account.js
profile.js
profile_templates.js
tilesets_viewer.js
keys_templates.js
keys_deps.js
keys.js
@ -154,6 +155,7 @@ module CartoDB
common_new.css
old_common.css
dashboard.css
tilesets_viewer.css
cartodb.css
front.css
editor.css

@ -5,10 +5,10 @@
* Note: don't modify its contents unless it's coordinated to work with deployments in different environments
*/
const CARTO_BUILDER_ASSET_HOST = JSON.stringify(process.env.CARTO_BUILDER_ASSET_HOST || '/assets');
const CARTO_MAPS_API_V2_EXTERNAL_URL = JSON.stringify(process.env.CARTO_MAPS_API_V2_EXTERNAL_URL || 'http://localhost.lan:8282');
const CARTO_BUILDER_ASSET_HOST = process.env.CARTO_BUILDER_ASSET_HOST || '';
const CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE = process.env.CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE || 'http://localhost.lan:8282';
module.exports = {
'CARTO_BUILDER_ASSET_HOST': CARTO_BUILDER_ASSET_HOST,
'CARTO_MAPS_API_V2_EXTERNAL_URL': CARTO_MAPS_API_V2_EXTERNAL_URL
'CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE': CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE
};

@ -341,6 +341,7 @@ CartoDB::Application.routes.draw do
get '(/user/:user_domain)(/u/:user_domain)/dashboard/get-started/:id' => 'visualizations#index', as: :get_started_onboarding
# Tileset viewer
get '/viewer/user/:user_domain/:type' => 'tilesets_viewer#index', as: :public_tilesets_viewer
get '(/user/:user_domain)(/u/:user_domain)/dashboard/tilesets/:id' => 'visualizations#index', as: :tilesets_viewer, constraints: { id: /[0-z.-]+/ }
# Public dashboard

@ -12,12 +12,12 @@ module.exports = {
}
}
return window.StaticConfig.assetVersion || window.CartoConfig.data.user_frontend_version || version;
return window.StaticConfig.assetVersion || (window.CartoConfig && window.CartoConfig.data && window.CartoConfig.data.user_frontend_version) || version;
},
getAssetsBaseUrl: function () {
const data = window.CartoConfig.data;
const dataAssetsHost = data.asset_host && data.asset_host + '/assets';
const dataAssetsHost = data && data.asset_host ? data.asset_host + '/assets' : '';
const assetsBaseUrl =
window.StaticConfig.assetsBaseUrl ||

@ -2,10 +2,11 @@ var CartoNode = require('../../../../../vendor/assets/javascripts/carto-node/car
var UrlHelper = require('./helpers/url');
var Redirector = require('../helpers/redirector');
/* global __ASSETS_VERSION__:false */
// __ASSETS_VERSION__ is injected via Webpack to avoid requiring
// whole package.json file
/* global __ASSETS_VERSION__:false, __CARTO_BUILDER_ASSET_HOST__:false */
// __ASSETS_VERSION__ is injected via Webpack to avoid requiring whole package.json file
// __CARTO_BUILDER_ASSET_HOST__ is also injected via Webpack
var version = __ASSETS_VERSION__;
var CARTO_BUILDER_ASSET_HOST = __CARTO_BUILDER_ASSET_HOST__;
var AssetsVersionHelper = require('../helpers/assets-version');
var GOOGLE_MAPS_SCRIPT_SRC = '//maps.googleapis.com/maps/api/js?v=3.32&sensor=false';
@ -60,7 +61,7 @@ window.CartoConfig = window.CartoConfig || {};
var getAssetsToLoad = function (userData) {
var entryPointFeatureFlags = getEntryPointFeatureFlags(window.StaticConfig);
var userFeatureFlags = userData.feature_flags;
var userFeatureFlags = userData ? userData.feature_flags : [];
var featureFlagToUse = entryPointFeatureFlags.filter(function (featureFlag) {
return userFeatureFlags.indexOf(featureFlag) !== -1;
@ -124,6 +125,17 @@ window.CartoConfig = window.CartoConfig || {};
})(window, document, assetsUrl, '/favicons/favicon.ico', options.stylesheets, options.scripts);
};
var markAsReady = function (userData) {
assetsUrl = AssetsVersionHelper.getAssetsUrl(version);
addSpinner();
var assets = getAssetsToLoad(userData);
addAssets({
stylesheets: assets.stylesheets,
scripts: assets.scripts
});
};
var getUserConfig = function (visualizationError) {
client.getConfig(function (err, response, data) {
if (err) {
@ -158,14 +170,8 @@ window.CartoConfig = window.CartoConfig || {};
}
window.CartoConfig.data = data;
assetsUrl = AssetsVersionHelper.getAssetsUrl(version);
addSpinner();
var assets = getAssetsToLoad(userData);
addAssets({
stylesheets: assets.stylesheets,
scripts: assets.scripts
});
markAsReady(userData);
});
};
@ -193,6 +199,11 @@ window.CartoConfig = window.CartoConfig || {};
if (window.StaticConfig.visualization) {
getVisualization(window.StaticConfig.visualization.params);
} else if (window.StaticConfig.anonymous) {
const isRootLevel = CARTO_BUILDER_ASSET_HOST === '//';
const baseUrl = isRootLevel ? '/assets' : CARTO_BUILDER_ASSET_HOST + '/assets';
window.StaticConfig.assetsBaseUrl = baseUrl;
markAsReady();
} else {
getUserConfig();
}

@ -53,7 +53,8 @@ export default {
let tileset;
try {
tileset = await this.$store.dispatch('tilesets/getTileset', { source: this.source, tileset_id: this.tileset_id, project_id, dataset_id, connection_id });
} catch {}
} catch (e) {
}
const center = tileset && tileset.metadata && tileset.metadata.center && tileset.metadata.center.split(',');
const longitude = center && parseFloat(center[0]);
const latitude = center && parseFloat(center[1]);
@ -70,7 +71,7 @@ export default {
this.$router.push({ name: 'tilesets' });
},
shareOptions: {
baseUrl: `https://viewer.carto${this.base_url.includes('staging') ? '-staging' : ''}.com`,
baseUrl: `${this.base_url}/viewer`,
privacy: tileset.privacy,
setPrivacy: this.setPrivacy
}

@ -0,0 +1,43 @@
<template>
<div ref="viewer">
</div>
</template>
<script>
import init from '@carto/viewer/src/init';
/* global __CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE__:false */
// __CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE__ is injected via Webpack
const CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE = __CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE__;
export default {
name: 'App',
mounted () {
this.mountViewer();
},
methods: {
async mountViewer () {
const element = this.$refs.viewer;
const { username, type } = this.getUsernameType();
this.props = {
username: username,
type: type,
mapsUrl: CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE,
query: new URLSearchParams(window.location.search),
goBackFunction: () => {
window.location = '/';
}
};
init(element, this.props);
},
getUsernameType () {
const regex = /viewer\/user\/(.*)\/(.*)/.exec(window.location.pathname);
return { username: regex[1], type: regex[2] };
}
}
};
</script>
<style lang="scss" scoped>
</style>

@ -0,0 +1,15 @@
import Vue from 'vue';
import VueI18n from 'vue-i18n';
import en from 'new-dashboard/i18n/locales/en';
Vue.use(VueI18n);
const i18n = new VueI18n({
locale: 'en',
messages: {
en
}
});
export default i18n;

@ -0,0 +1,18 @@
import Vue from 'vue';
import App from './App.vue';
import i18n from './i18n';
import store from './store';
Vue.config.productionTip = false;
const el = '#app';
/* eslint-disable no-new */
new Vue({
el,
store,
i18n,
components: { App },
template: '<App />'
});

@ -0,0 +1,39 @@
/* Theme */
$color-primary: #2E51E8;
$color-primary--soft: #F2F6F9;
$color-primary--dark: #3D33CC;
@import '../new-dashboard/styles/variables';
// base
@import '../new-dashboard/styles/base/reset';
@import '../new-dashboard/styles/base/typography';
// layout
@import '../new-dashboard/styles/layout/cells';
@import '../new-dashboard/styles/layout/grid';
@import '../new-dashboard/styles/layout/page';
@import '../new-dashboard/styles/layout/section';
// components
@import '../new-dashboard/styles/components/buttons';
@import '../new-dashboard/styles/components/checkbox';
@import '../new-dashboard/styles/components/code';
@import '../new-dashboard/styles/components/welcome';
@import '../new-dashboard/styles/components/scrollbar';
// pages
@import '../new-dashboard/styles/pages/solutionsIcons';
@import '../new-dashboard/styles/pages/visualizations';
// helpers
@import '../new-dashboard/styles/helpers/colors';
@import '../new-dashboard/styles/helpers/flexbox';
@import '../new-dashboard/styles/helpers/spacing';
@import '../new-dashboard/styles/helpers/utilities';
//hangar
@import '../new-dashboard/styles/hangar/main';
//vendors
@import '../new-dashboard/styles/vendors/perfect-scrollbar';

@ -0,0 +1,15 @@
import Vue from 'vue';
import Vuex from 'vuex';
import catalog from 'new-dashboard/store/modules/data/catalog';
Vue.use(Vuex);
const store = new Vuex.Store({
state: {},
getters: {},
modules: {
catalog
}
});
export default store;

@ -11,6 +11,19 @@ var files = {
'/javascripts/new_dashboard.js'
]
},
tilesets_viewer: {
page: 'tilesets_viewer',
anonymous: true,
stylesheets: [
'/stylesheets/common_new.css',
'/stylesheets/tilesets_viewer.css'
],
scripts: [
'/javascripts/common.js',
'/javascripts/common_vendor.js',
'/javascripts/tilesets_viewer.js'
]
},
profile: {
page: 'profile',
stylesheets: [

@ -9,6 +9,7 @@ exports.task = function () {
'app/assets/stylesheets/editor-3/**/*.scss',
'app/assets/stylesheets/deep-insights/**/*.scss',
'app/assets/stylesheets/new_dashboard/**/*.scss',
'app/assets/stylesheets/tilesets_viewer/**/*.scss',
'node_modules/cartoassets/src/scss/**/*.scss',
'node_modules/internal-carto.js/themes/scss/**/*.scss'
],

2
package-lock.json generated

@ -1,6 +1,6 @@
{
"name": "cartodb-ui",
"version": "1.0.0-assets.235",
"version": "1.0.0-assets.236",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

@ -1,6 +1,6 @@
{
"name": "cartodb-ui",
"version": "1.0.0-assets.235",
"version": "1.0.0-assets.236",
"description": "CARTO UI frontend",
"repository": {
"type": "git",
@ -252,6 +252,7 @@
"dev:editor:cdb": "grunt editor-cdb",
"dev:static": "webpack --progress --watch --config webpack/static-pages/webpack.dev.config.js",
"dev:do-catalog": "NODE_ENV=development vue-cli-service serve --watch lib/assets/javascripts/do-catalog/main.js",
"dev:tilesets-viewer": "NODE_ENV=development vue-cli-service serve --watch lib/assets/javascripts/tilesets-viewer/main.js",
"profile": "NODE_ENV=production webpack --profile --json --config webpack/v4/webpack.prod.config.js > compilation-stats.json"
}
}

@ -10,6 +10,7 @@ module.exports = {
resolve: {
alias: {
'do-catalog': path.resolve(__dirname, 'lib/assets/javascripts/do-catalog/'),
'tilesets-viewer': path.resolve(__dirname, 'lib/assets/javascripts/tilesets-viewer/'),
'new-dashboard': path.resolve(__dirname, 'lib/assets/javascripts/new-dashboard/')
},
extensions: ['.js', '.vue', '.json', '.scss']

@ -20,9 +20,9 @@ module.exports = {
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin({
__ASSETS_VERSION__: `'${VERSION}'`,
__CARTO_BUILDER_ASSET_HOST__: PUBLIC_STATICS_CONFIG.CARTO_BUILDER_ASSET_HOST,
__CARTO_MAPS_API_V2_EXTERNAL_URL__: PUBLIC_STATICS_CONFIG.CARTO_MAPS_API_V2_EXTERNAL_URL
__ASSETS_VERSION__: JSON.stringify(VERSION),
__CARTO_BUILDER_ASSET_HOST__: JSON.stringify(PUBLIC_STATICS_CONFIG.CARTO_BUILDER_ASSET_HOST),
__CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE__: JSON.stringify(PUBLIC_STATICS_CONFIG.CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE)
}),
...Object.keys(webpackFiles.htmlFiles).map((entryName) => {
@ -34,5 +34,32 @@ module.exports = {
config: webpackFiles.htmlFiles[entryName]
});
})
]
],
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: [
'./node_modules/@carto/viewer'
],
exclude: [
'./node_modules/@carto/viewer/node_modules'
],
options: {
babelrc: true
}
},
{
test: /\.svg$/,
use: ['@svgr/webpack'],
include: [
'./node_modules/@carto/viewer'
],
exclude: [
'./node_modules/@carto/viewer/node_modules'
]
}
]
}
};

@ -27,6 +27,12 @@ const entries = {
rootDir('node_modules/internal-carto.js/themes/scss/entry.scss')
],
tilesets_viewer: [
rootDir('lib/assets/javascripts/tilesets-viewer/main.js'),
rootDir('lib/assets/javascripts/tilesets-viewer/main.scss'),
rootDir('node_modules/internal-carto.js/themes/scss/entry.scss')
],
header: [
rootDir('lib/assets/javascripts/new-dashboard/bundles/header/header.js'),
rootDir('lib/assets/javascripts/new-dashboard/styles/bundles/header.scss')

@ -4,6 +4,7 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
const WebpackDeleteAfterEmit = require('webpack-delete-after-emit');
const { version } = require('../../package.json');
const { http_path_prefix } = require(`../../config/grunt_${process.env.NODE_ENV}.json`);
const PUBLIC_STATICS_CONFIG = require('../../config/public_statics_config');
const entryPoints = require('./entryPoints');
const vueLoaderConfig = require('../new-dashboard/vue-loader.conf');
@ -42,7 +43,8 @@ module.exports = {
__ENV__: JSON.stringify('prod'),
__ASSETS_VERSION__: JSON.stringify(version),
__ASSETS_PATH__: JSON.stringify(`${http_path_prefix}/assets/${version}`),
__KEPLERGL_BASE_URL__: JSON.stringify('https://kepler.gl')
__KEPLERGL_BASE_URL__: JSON.stringify('https://kepler.gl'),
__CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE__: JSON.stringify(PUBLIC_STATICS_CONFIG.CARTO_MAPS_API_V2_EXTERNAL_URL_TEMPLATE)
}),
new MiniCssExtractPlugin({

Loading…
Cancel
Save