Skip to content

Commit

Permalink
Hide ribbon and favoriting UI for now
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed Mar 27, 2019
1 parent d76baa9 commit 4afd29a
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 10 deletions.
1 change: 1 addition & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ en:
undo_redo: Undo / Redo
recent: Recent
favorites: Favorites
add_feature: Add Feature
modes:
add_feature:
title: Add a feature
Expand Down
3 changes: 2 additions & 1 deletion dist/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"inspect": "Inspect",
"undo_redo": "Undo / Redo",
"recent": "Recent",
"favorites": "Favorites"
"favorites": "Favorites",
"add_feature": "Add Feature"
},
"modes": {
"add_feature": {
Expand Down
4 changes: 2 additions & 2 deletions modules/ui/preset_favorite_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export function uiPresetFavoriteButton(preset, geom, context, klass) {


presetFavorite.button = function(selection) {

var canFavorite = geom !== 'relation' && preset.searchable !== false;
// disable favoriting for now
var canFavorite = false;//geom !== 'relation' && preset.searchable !== false;

_button = selection.selectAll('.preset-favorite-button')
.data(canFavorite ? [0] : []);
Expand Down
1 change: 1 addition & 0 deletions modules/ui/tools/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './add_favorite';
export * from './add_recent';
export * from './modes';
export * from './notes';
export * from './save';
export * from './search_add';
Expand Down
161 changes: 161 additions & 0 deletions modules/ui/tools/modes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import _debounce from 'lodash-es/debounce';

import { select as d3_select } from 'd3-selection';

import {
modeAddArea,
modeAddLine,
modeAddPoint,
modeBrowse
} from '../../modes';

import { t } from '../../util/locale';
import { svgIcon } from '../../svg';
import { tooltip } from '../../util/tooltip';
import { uiTooltipHtml } from '../tooltipHtml';

export function uiToolOldDrawModes(context) {

var tool = {
id: 'old_modes',
label: t('toolbar.add_feature')
};

var modes = [
modeAddPoint(context, {
title: t('modes.add_point.title'),
button: 'point',
description: t('modes.add_point.description'),
preset: context.presets().item('point'),
key: '1'
}),
modeAddLine(context, {
title: t('modes.add_line.title'),
button: 'line',
description: t('modes.add_line.description'),
preset: context.presets().item('line'),
key: '2'
}),
modeAddArea(context, {
title: t('modes.add_area.title'),
button: 'area',
description: t('modes.add_area.description'),
preset: context.presets().item('area'),
key: '3'
})
];


function enabled() {
return osmEditable();
}

function osmEditable() {
var mode = context.mode();
return context.editable() && mode && mode.id !== 'save';
}

modes.forEach(function(mode) {
context.keybinding().on(mode.key, function() {
if (!enabled(mode)) return;

if (mode.id === context.mode().id) {
context.enter(modeBrowse(context));
} else {
context.enter(mode);
}
});
});

tool.render = function(selection) {

var wrap = selection
.append('div')
.attr('class', 'joined')
.style('display', 'flex');

context
.on('enter.editor', function(entered) {
selection.selectAll('button.add-button')
.classed('active', function(mode) { return entered.button === mode.button; });
context.container()
.classed('mode-' + entered.id, true);
});

context
.on('exit.editor', function(exited) {
context.container()
.classed('mode-' + exited.id, false);
});


var debouncedUpdate = _debounce(update, 500, { leading: true, trailing: true });

context.map()
.on('move.modes', debouncedUpdate)
.on('drawn.modes', debouncedUpdate);

context
.on('enter.modes', update);

update();


function update() {

var buttons = wrap.selectAll('button.add-button')
.data(modes, function(d) { return d.id; });

// exit
buttons.exit()
.remove();

// enter
var buttonsEnter = buttons.enter()
.append('button')
.attr('tabindex', -1)
.attr('class', function(d) { return d.id + ' add-button bar-button'; })
.on('click.mode-buttons', function(d) {
if (!enabled(d)) return;

// When drawing, ignore accidental clicks on mode buttons - #4042
var currMode = context.mode().id;
if (/^draw/.test(currMode)) return;

if (d.id === currMode) {
context.enter(modeBrowse(context));
} else {
context.enter(d);
}
})
.call(tooltip()
.placement('bottom')
.html(true)
.title(function(d) { return uiTooltipHtml(d.description, d.key); })
);

buttonsEnter
.each(function(d) {
d3_select(this)
.call(svgIcon('#iD-icon-' + d.button));
});

buttonsEnter
.append('span')
.attr('class', 'label')
.text(function(mode) { return mode.title; });

// if we are adding/removing the buttons, check if toolbar has overflowed
if (buttons.enter().size() || buttons.exit().size()) {
context.ui().checkOverflow('#bar', true);
}

// update
buttons = buttons
.merge(buttonsEnter)
.classed('disabled', function(d) { return !enabled(d); });
}
};

return tool;
}
16 changes: 9 additions & 7 deletions modules/ui/top_toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import {
} from 'd3-selection';

import _debounce from 'lodash-es/debounce';
import { uiToolAddFavorite, uiToolAddRecent, uiToolNotes, uiToolSave, uiToolSearchAdd, uiToolSidebarToggle, uiToolUndoRedo } from './tools';
import { /*uiToolAddFavorite, uiToolAddRecent, uiToolSearchAdd, */ uiToolOldDrawModes, uiToolNotes, uiToolSave, uiToolSidebarToggle, uiToolUndoRedo } from './tools';


export function uiTopToolbar(context) {

var sidebarToggle = uiToolSidebarToggle(context),
searchAdd = uiToolSearchAdd(context),
addFavorite = uiToolAddFavorite(context),
addRecent = uiToolAddRecent(context),
modes = uiToolOldDrawModes(context),
//searchAdd = uiToolSearchAdd(context),
//addFavorite = uiToolAddFavorite(context),
//addRecent = uiToolAddRecent(context),
notes = uiToolNotes(context),
undoRedo = uiToolUndoRedo(context),
save = uiToolSave(context);
Expand All @@ -39,16 +40,17 @@ export function uiTopToolbar(context) {
var tools = [
sidebarToggle,
'spacer',
searchAdd
modes
// searchAdd
];

/*
if (context.presets().getFavorites().length > 0) {
tools.push(addFavorite);
}
if (addRecent.shouldShow()) {
tools.push(addRecent);
}
}*/

tools.push('spacer');

Expand Down

0 comments on commit 4afd29a

Please sign in to comment.