Initial commit
This commit is contained in:
22
lib/assets/javascripts/dashboard/common/analytics-pusher.js
Normal file
22
lib/assets/javascripts/dashboard/common/analytics-pusher.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Send events to Google Analytics if it is available
|
||||
* - https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits
|
||||
*
|
||||
* *Remove this "helper" when dashboard is deprecated
|
||||
*/
|
||||
|
||||
var GAPusher = function (opts) {
|
||||
var ga = window.ga;
|
||||
opts = opts || {};
|
||||
|
||||
if (ga) {
|
||||
ga(opts.eventName || 'send', {
|
||||
hitType: opts.hitType,
|
||||
eventCategory: opts.eventCategory,
|
||||
eventAction: opts.eventAction,
|
||||
eventLabel: opts.eventLabel
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = GAPusher;
|
||||
60
lib/assets/javascripts/dashboard/common/router-base.js
Normal file
60
lib/assets/javascripts/dashboard/common/router-base.js
Normal file
@@ -0,0 +1,60 @@
|
||||
var _ = require('underscore');
|
||||
var Backbone = require('backbone');
|
||||
|
||||
/**
|
||||
* @extends http://backbonejs.org/#Router With some common functionality in the context of this app.
|
||||
*/
|
||||
var RouterBase = Backbone.Router.extend({
|
||||
|
||||
/**
|
||||
* Placeholder, is replaced by enableAfterMainView().
|
||||
*/
|
||||
navigate: function () {
|
||||
throw new Error('router.enableAfterMainView({ ... }) must be called before you can navigate');
|
||||
},
|
||||
|
||||
/**
|
||||
* Enable router to monitor and manage browser URL and history.
|
||||
* Expected to be called after main view as the function name indicates,
|
||||
*/
|
||||
enableAfterMainView: function () {
|
||||
/**
|
||||
* @override http://backbonejs.org/#Router-navigate Allow
|
||||
* @param fragmentOrUrl {String} Either a fragment (e.g. '/dashboard/datasets') or a full URL
|
||||
* (e.g. http://user.carto.com/dashboard/datasets), the navigate method takes care to route correctly.
|
||||
*/
|
||||
this.navigate = function (fragmentOrUrl, opts) {
|
||||
Backbone.Router.prototype.navigate.call(this, this.normalizeFragmentOrUrl(fragmentOrUrl), opts);
|
||||
};
|
||||
|
||||
Backbone.history.start({
|
||||
pushState: true,
|
||||
root: this.rootPath() + '/' // Yes, this trailing slash is necessary for the router to update the history state properly.
|
||||
});
|
||||
},
|
||||
|
||||
rootPath: function () {
|
||||
throw new Error('implement rootPath in child router (no trailing slash)');
|
||||
},
|
||||
|
||||
/**
|
||||
* Normalise a given fragment or URL for navigation mechanisms to work.
|
||||
* Typically, remove the leading base URL from the given fragment or URL.
|
||||
*
|
||||
* @param {String} fragmentOrUrl
|
||||
* @return {String}
|
||||
*/
|
||||
normalizeFragmentOrUrl: function (fragmentOrUrl) {
|
||||
throw new Error('implement normalizeFragmentOrUrl in child router');
|
||||
}
|
||||
});
|
||||
|
||||
RouterBase.supportTrailingSlashes = function (obj) {
|
||||
return _.reduce(obj, function (res, val, key) {
|
||||
res[key] = val;
|
||||
res[key + '/'] = val;
|
||||
return res;
|
||||
}, {});
|
||||
};
|
||||
|
||||
module.exports = RouterBase;
|
||||
@@ -0,0 +1,140 @@
|
||||
const RouterBase = require('dashboard/common/router-base');
|
||||
const RouterModel = require('dashboard/views/organization/groups-admin/router-model');
|
||||
const GroupHeaderView = require('dashboard/views/organization/groups-admin/group-header/group-header-view');
|
||||
const GroupsIndexView = require('dashboard/views/organization/groups-admin/group-index/group-index-view');
|
||||
const CreateGroupView = require('dashboard/views/organization/groups-admin/create-group/create-group-view');
|
||||
const GroupUsersView = require('dashboard/views/organization/groups-admin/group-users/group-users-view');
|
||||
const EditGroupView = require('dashboard/views/organization/groups-admin/edit-group/edit-group-view');
|
||||
const ViewFactory = require('builder/components/view-factory');
|
||||
|
||||
const checkAndBuildOpts = require('builder/helpers/required-opts');
|
||||
|
||||
const REQUIRED_OPTS = [
|
||||
'rootUrl',
|
||||
'groups',
|
||||
'userModel',
|
||||
'flashMessageModel',
|
||||
'modals'
|
||||
];
|
||||
|
||||
/**
|
||||
* Backbone router for organization groups urls.
|
||||
*/
|
||||
module.exports = RouterBase.extend({
|
||||
|
||||
routes: RouterBase.supportTrailingSlashes({
|
||||
'': 'renderGroupsIndex',
|
||||
'new': 'renderCreateGroup',
|
||||
':id': 'renderGroupUsers',
|
||||
':id/edit': 'renderEditGroup',
|
||||
|
||||
// If URL is lacking the trailing slash (e.g. 'http://username.carto.com/organization/groups'), treat it like index
|
||||
'*prefix/groups': 'renderGroupsIndex'
|
||||
}),
|
||||
|
||||
initialize: function (options) {
|
||||
checkAndBuildOpts(options, REQUIRED_OPTS, this);
|
||||
|
||||
this.rootPath = this._rootUrl.pathname.bind(this._rootUrl);
|
||||
|
||||
this.model = new RouterModel();
|
||||
this.model.createLoadingView('Loading view'); // Until router's history is started
|
||||
this.listenTo(this.model, 'change', this._onChange);
|
||||
},
|
||||
|
||||
normalizeFragmentOrUrl: function (fragmentOrUrl) {
|
||||
return fragmentOrUrl ? fragmentOrUrl.toString().replace(this._rootUrl.toString(), '') : '';
|
||||
},
|
||||
|
||||
isWithinCurrentRoutes: function (url) {
|
||||
return url.indexOf(this._rootUrl.pathname()) !== -1;
|
||||
},
|
||||
|
||||
renderGroupsIndex: function () {
|
||||
this.model.set('view',
|
||||
new GroupsIndexView({
|
||||
newGroupUrl: this._groupUrl.bind(this),
|
||||
groups: this._groups,
|
||||
router: this
|
||||
})
|
||||
);
|
||||
},
|
||||
|
||||
renderCreateGroup: function () {
|
||||
const group = this._groups.newGroupById();
|
||||
|
||||
this.model.set('view',
|
||||
ViewFactory.createListView([
|
||||
() => this._createGroupHeader(group),
|
||||
|
||||
() => new CreateGroupView({
|
||||
flashMessageModel: this._flashMessageModel,
|
||||
group,
|
||||
onCreated: this._navigateToGroup.bind(this, group)
|
||||
})
|
||||
])
|
||||
);
|
||||
},
|
||||
|
||||
renderGroupUsers: function (id) {
|
||||
this.model.createGroupView(this._groups, id, group => {
|
||||
return ViewFactory.createListView([
|
||||
() => this._createGroupHeader(group, 'group_users'),
|
||||
|
||||
() => new GroupUsersView({
|
||||
group,
|
||||
orgUsers: this._userModel.organization.users,
|
||||
userModel: this._userModel
|
||||
})
|
||||
]);
|
||||
});
|
||||
},
|
||||
|
||||
renderEditGroup: function (id) {
|
||||
this.model.createGroupView(this._groups, id, group => {
|
||||
return ViewFactory.createListView([
|
||||
() => this._createGroupHeader(group, 'edit_group'),
|
||||
|
||||
() => new EditGroupView({
|
||||
group,
|
||||
flashMessageModel: this._flashMessageModel,
|
||||
modals: this._modals,
|
||||
userModel: this._userModel,
|
||||
onSaved: this._navigateToGroup.bind(this, group),
|
||||
onDeleted: this.navigate.bind(this, this._rootUrl, { trigger: true })
|
||||
})
|
||||
]);
|
||||
});
|
||||
},
|
||||
|
||||
_navigateToGroup: function (group) {
|
||||
this.navigate(this._rootUrl.urlToPath(group.id), { trigger: true });
|
||||
},
|
||||
|
||||
_groupUrl: function (group, subpath) {
|
||||
var path = group.id;
|
||||
|
||||
if (subpath) {
|
||||
path += '/' + subpath;
|
||||
}
|
||||
|
||||
return this._rootUrl.urlToPath(path);
|
||||
},
|
||||
|
||||
_createGroupHeader: function (group, current) {
|
||||
var urls = {
|
||||
root: this._rootUrl,
|
||||
users: this._groupUrl(group),
|
||||
edit: this._groupUrl(group, 'edit')
|
||||
};
|
||||
urls.users.isCurrent = current === 'group_users';
|
||||
urls.edit.isCurrent = current === 'edit_group';
|
||||
|
||||
return new GroupHeaderView({ group, urls });
|
||||
},
|
||||
|
||||
_onChange: function () {
|
||||
this._flashMessageModel.hide();
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
const Backbone = require('backbone');
|
||||
|
||||
/**
|
||||
* New public table router \o/
|
||||
*
|
||||
* - No more /#/xxx routes
|
||||
*/
|
||||
|
||||
module.exports = Backbone.Router.extend({
|
||||
|
||||
routes: {
|
||||
':id/public/:scenario': 'change'
|
||||
},
|
||||
|
||||
initialize: function (table) {
|
||||
this.table = table;
|
||||
},
|
||||
|
||||
change: function (_id, scenario) {
|
||||
// Check active view, if it is different, change
|
||||
if (scenario != 'table' && scenario != 'map') scenario = 'table'; // eslint-disable-line eqeqeq
|
||||
this.table.workViewMobile.active(scenario);
|
||||
}
|
||||
});
|
||||
46
lib/assets/javascripts/dashboard/common/upload-config.js
Normal file
46
lib/assets/javascripts/dashboard/common/upload-config.js
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
/**
|
||||
* Default upload config
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
uploadStates: [
|
||||
'enqueued',
|
||||
'pending',
|
||||
'importing',
|
||||
'uploading',
|
||||
'guessing',
|
||||
'unpacking',
|
||||
'getting',
|
||||
'creating',
|
||||
'complete'
|
||||
],
|
||||
fileExtensions: [
|
||||
'csv',
|
||||
'xls',
|
||||
'xlsx',
|
||||
'zip',
|
||||
'kml',
|
||||
'geojson',
|
||||
'json',
|
||||
'ods',
|
||||
'kmz',
|
||||
'tsv',
|
||||
'gpx',
|
||||
'tar',
|
||||
'gz',
|
||||
'tgz',
|
||||
'osm',
|
||||
'bz2',
|
||||
'tif',
|
||||
'tiff',
|
||||
'txt',
|
||||
'sql',
|
||||
'rar',
|
||||
'carto',
|
||||
'gpkg'
|
||||
],
|
||||
// How big should file be?
|
||||
fileTimesBigger: 3
|
||||
};
|
||||
10
lib/assets/javascripts/dashboard/common/wkt.js
Normal file
10
lib/assets/javascripts/dashboard/common/wkt.js
Normal file
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
types: [
|
||||
'POINT',
|
||||
'LINESTRING',
|
||||
'POLYGON',
|
||||
'MULTIPOINT',
|
||||
'MULTILINESTRING',
|
||||
'MULTIPOLYGON'
|
||||
]
|
||||
};
|
||||
Reference in New Issue
Block a user