Skip to content

Commit

Permalink
move widget type and board components to ui-land.
Browse files Browse the repository at this point in the history
  • Loading branch information
artasparks committed Jun 9, 2016
1 parent 9c45d4c commit c1da033
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 85 deletions.
25 changes: 0 additions & 25 deletions src/glift-core/util/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,31 +125,6 @@ glift.enums.showVariations = {
MORE_THAN_ONE: 'MORE_THAN_ONE'
};

/**
* The types of widgets users can create. Used to link Controllers and Options.
* @enum {string}
*/
glift.enums.widgetTypes = {
CORRECT_VARIATIONS_PROBLEM: 'CORRECT_VARIATIONS_PROBLEM',
EXAMPLE: 'EXAMPLE',
GAME_VIEWER: 'GAME_VIEWER',
REDUCED_GAME_VIEWER: 'REDUCED_GAME_VIEWER',
STANDARD_PROBLEM: 'STANDARD_PROBLEM',
BOARD_EDITOR: 'BOARD_EDITOR'
};

/**
* The types of components that exist in the Glift UI.
* @enum {string}
*/
glift.enums.boardComponents = {
BOARD: 'BOARD',
COMMENT_BOX: 'COMMENT_BOX',
EXTRA_ICONBAR: 'EXTRA_ICONBAR',
ICONBAR: 'ICONBAR',
STATUS_BAR: 'STATUS_BAR'
};

/**
* Rotations we can apply to Go Boards. Doesn't rotate the fundamental data (the
* SGF points), but rotates at the time the board is drawn.
Expand Down
4 changes: 2 additions & 2 deletions src/glift-ui/api/api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
ok(sgfObj !== undefined);
deepEqual(sgfObj.sgfString, testdata.sgfs.complexproblem);
deepEqual(sgfObj.initialPosition, '');
deepEqual(sgfObj.widgetType, glift.enums.widgetTypes.GAME_VIEWER);
deepEqual(sgfObj.widgetType, glift.WidgetType.GAME_VIEWER);
manager.destroy();
});

test('Succesfully create a complex problem series', function() {
var wtypes = glift.enums.widgetTypes;
var wtypes = glift.WidgetType;
var sgfs = testdata.sgfs;
// TODO(kashomon): Do more extensive integration testing here.
var manager = glift.api.create({
Expand Down
2 changes: 1 addition & 1 deletion src/glift-ui/api/icon_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ glift.api.iconActionDefaults = {
click: function(event, widget, icon, iconBar) {
var manager = widget.manager;
var sgfObj = {
widgetType: glift.enums.widgetTypes.GAME_VIEWER,
widgetType: glift.WidgetType.GAME_VIEWER,
initialPosition: widget.controller.initialPosition,
sgfString: widget.controller.originalSgf(),
showVariations: glift.enums.showVariations.ALWAYS,
Expand Down
14 changes: 7 additions & 7 deletions src/glift-ui/api/sgf_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ glift.api.SgfOptions = function(opt_o) {
*
* api:1.0
*
* @const {glift.enums.widgetTypes}
* @const {glift.WidgetType}
*/
this.widgetType = o.widgetType || glift.enums.widgetTypes.GAME_VIEWER;
this.widgetType = o.widgetType || glift.WidgetType.GAME_VIEWER;

/**
* Defines where to start on the go board. An empty string implies the very
Expand Down Expand Up @@ -157,13 +157,13 @@ glift.api.SgfOptions = function(opt_o) {
* The UI Components to use for this display.
*
* api:1.0
* @const {!Array<glift.enums.boardComponents>}
* @const {!Array<glift.BoardComponent>}
*/
this.uiComponents = o.uiComponents || [
glift.enums.boardComponents.BOARD,
glift.enums.boardComponents.COMMENT_BOX,
glift.enums.boardComponents.STATUS_BAR,
glift.enums.boardComponents.ICONBAR
glift.BoardComponent.BOARD,
glift.BoardComponent.COMMENT_BOX,
glift.BoardComponent.STATUS_BAR,
glift.BoardComponent.ICONBAR
];

/**
Expand Down
10 changes: 5 additions & 5 deletions src/glift-ui/api/sgf_options_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
url: undefined,
alias: undefined,
parseType: glift.parse.parseType.SGF,
widgetType: glift.enums.widgetTypes.GAME_VIEWER,
widgetType: glift.WidgetType.GAME_VIEWER,
initialPosition: '',
boardRegion: glift.enums.boardRegions.AUTO,
nextMovesPath: '',
Expand All @@ -22,10 +22,10 @@
ARROW_RIGHT: 'iconActions.chevron-right.click'
},
uiComponents: [
glift.enums.boardComponents.BOARD,
glift.enums.boardComponents.COMMENT_BOX,
glift.enums.boardComponents.STATUS_BAR,
glift.enums.boardComponents.ICONBAR
glift.BoardComponent.BOARD,
glift.BoardComponent.COMMENT_BOX,
glift.BoardComponent.STATUS_BAR,
glift.BoardComponent.ICONBAR
],
disableStatusBar: false,
disableBoard: false,
Expand Down
2 changes: 1 addition & 1 deletion src/glift-ui/api/widgetopt/board_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Board Editor options.
*/
glift.api.widgetopt[glift.enums.widgetTypes.BOARD_EDITOR] = {
glift.api.widgetopt[glift.WidgetType.BOARD_EDITOR] = {
_markMap: {
bstone_a: glift.enums.marks.LABEL_ALPHA,
bstone_1: glift.enums.marks.LABEL_NUMERIC,
Expand Down
2 changes: 1 addition & 1 deletion src/glift-ui/api/widgetopt/correct_variations_problem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Additional Options for the GameViewers
*/
glift.api.widgetopt[glift.enums.widgetTypes.CORRECT_VARIATIONS_PROBLEM] = {
glift.api.widgetopt[glift.WidgetType.CORRECT_VARIATIONS_PROBLEM] = {
markLastMove: undefined, // rely on defaults
keyMappings: undefined, // rely on defaults
enableMousewheel: undefined, // rely on defaults (false)
Expand Down
2 changes: 1 addition & 1 deletion src/glift-ui/api/widgetopt/example_options.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Additional Options for EXAMPLEs
*/
glift.api.widgetopt[glift.enums.widgetTypes.EXAMPLE] = {
glift.api.widgetopt[glift.WidgetType.EXAMPLE] = {
markLastMove: undefined, // rely on defaults
keyMappings: undefined, // rely on defaults
enableMousewheel: undefined, // rely on defaults (false)
Expand Down
2 changes: 1 addition & 1 deletion src/glift-ui/api/widgetopt/game_viewer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Additional Options for the GameViewers
*/
glift.api.widgetopt[glift.enums.widgetTypes.GAME_VIEWER] = {
glift.api.widgetopt[glift.WidgetType.GAME_VIEWER] = {
markLastMove: true,
enableMousewheel: true,

Expand Down
2 changes: 1 addition & 1 deletion src/glift-ui/api/widgetopt/reduced_game_viewer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Game Viewer options for when used as part of a widget
*/
glift.api.widgetopt[glift.enums.widgetTypes.REDUCED_GAME_VIEWER] = {
glift.api.widgetopt[glift.WidgetType.REDUCED_GAME_VIEWER] = {
markLastMove: undefined, // rely on defaults
keyMappings: undefined, // rely on defaults
enableMousewheel: true,
Expand Down
2 changes: 1 addition & 1 deletion src/glift-ui/api/widgetopt/standard_problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Additional options for the standard problems, where the entire problem is
* stored client-side.
*/
glift.api.widgetopt[glift.enums.widgetTypes.STANDARD_PROBLEM] = {
glift.api.widgetopt[glift.WidgetType.STANDARD_PROBLEM] = {
markLastMove: undefined, // rely on defaults
keyMappings: undefined, // rely on defaults
enableMousewheel: undefined, // rely on defaults (false)
Expand Down
2 changes: 1 addition & 1 deletion src/glift-ui/api/widgetopt/widgetopt.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ goog.provide('glift.api.widgetopt');
/**
* A collection of widget options keyed by widget types.
*
* @type {!Object<glift.enums.widgetTypes, glift.api.WidgetTypeOptions>}
* @type {!Object<glift.WidgetType, glift.api.WidgetTypeOptions>}
*/
glift.api.widgetopt = {};
12 changes: 6 additions & 6 deletions src/glift-ui/api/widgetopt/widgetopt_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

// List of supported widget types in the Options rewrite.
var supportedList = [
glift.enums.widgetTypes.BOARD_EDITOR,
glift.enums.widgetTypes.CORRECT_VARIATIONS_PROBLEM,
glift.enums.widgetTypes.EXAMPLE,
glift.enums.widgetTypes.GAME_VIEWER,
glift.enums.widgetTypes.REDUCED_GAME_VIEWER,
glift.enums.widgetTypes.STANDARD_PROBLEM,
glift.WidgetType.BOARD_EDITOR,
glift.WidgetType.CORRECT_VARIATIONS_PROBLEM,
glift.WidgetType.EXAMPLE,
glift.WidgetType.GAME_VIEWER,
glift.WidgetType.REDUCED_GAME_VIEWER,
glift.WidgetType.STANDARD_PROBLEM,
];

var keys = [
Expand Down
14 changes: 14 additions & 0 deletions src/glift-ui/board_component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
goog.provide('glift.BoardComponent');

/**
* The types of UI components that exist in the Glift UI.
*
* @enum {string}
*/
glift.BoardComponent = {
BOARD: 'BOARD',
COMMENT_BOX: 'COMMENT_BOX',
EXTRA_ICONBAR: 'EXTRA_ICONBAR',
ICONBAR: 'ICONBAR',
STATUS_BAR: 'STATUS_BAR'
};
10 changes: 5 additions & 5 deletions src/glift-ui/displays/position/widget_boxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ glift.displays.position.WidgetBoxes.prototype = {

/**
* Get a component by ID.
* @param {glift.enums.boardComponents} key Component key
* @param {glift.BoardComponent} key Component key
* @return {?glift.orientation.BoundingBox} A bounding box or null.
*/
getBbox: function(key) {
Expand All @@ -52,7 +52,7 @@ glift.displays.position.WidgetBoxes.prototype = {
/**
* Get the bbox of a component or throw an exception
*
* @param {glift.enums.boardComponents} key Component key
* @param {glift.BoardComponent} key Component key
* @return {!glift.orientation.BoundingBox}.
*/
mustGetBbox: function(key) {
Expand Down Expand Up @@ -135,7 +135,7 @@ glift.displays.position.WidgetColumn = function() {
glift.displays.position.WidgetColumn.prototype = {
/** Set a mapping from from component to bounding box. */
setComponent: function(component, bbox) {
if (!glift.enums.boardComponents[component]) {
if (!glift.BoardComponent[component]) {
throw new Error('Unknown component: ' + component);
}
this.mapping[component] = bbox;
Expand All @@ -145,7 +145,7 @@ glift.displays.position.WidgetColumn.prototype = {
/**
* Get the bbox of a component or return null.
*
* @param {glift.enums.boardComponents} component Component key
* @param {glift.BoardComponent} component Component key
* @return {?glift.orientation.BoundingBox} A bounding box or null.
*/
getBbox: function(component) {
Expand All @@ -155,7 +155,7 @@ glift.displays.position.WidgetColumn.prototype = {
/**
* Get the bbox of a component or throw an exception.
*
* @param {glift.enums.boardComponents} component Component key
* @param {glift.BoardComponent} component Component key
* @return {!glift.orientation.BoundingBox}
*/
mustGetBbox: function(component) {
Expand Down
2 changes: 1 addition & 1 deletion src/glift-ui/displays/position/widget_boxes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
var defaultBbox3 = glift.orientation.bbox.fromPts(
glift.util.point(10, 10),
glift.util.point(150, 300));
var comps = glift.enums.boardComponents;
var comps = glift.BoardComponent;

var make = function(opts) {
return new glift.displays.position.WidgetBoxes();
Expand Down
4 changes: 2 additions & 2 deletions src/glift-ui/displays/position/widget_positioner.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ glift.displays.position.WidgetPositioner.prototype = {
var divBox = this.divBox,
boardRegion = this.boardRegion,
componentSet = this.componentSet,
comps = glift.enums.boardComponents,
comps = glift.BoardComponent,
hwRatio = divBox.height() / divBox.width(),
longBoxRegions = { TOP: true, BOTTOM: true };
if (!componentSet[comps.COMMENT_BOX] ||
Expand Down Expand Up @@ -161,7 +161,7 @@ glift.displays.position.WidgetPositioner.prototype = {
calculateColumn: function(recalCol, wrapperDiv, alignment, startTop) {
var top = startTop || 0;
var column = new glift.displays.position.WidgetColumn();
var components = glift.enums.boardComponents;
var components = glift.BoardComponent;
var divBoxSplits = [wrapperDiv];
var ratios = this._extractRatios(recalCol);
column.setOrderingFromRatioArray(recalCol);
Expand Down
6 changes: 3 additions & 3 deletions src/glift-ui/displays/position/widget_positioner_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
module('glift.displays.position.widgetPositionerTest');
var point = glift.util.point;
var components = glift.enums.boardComponents;
var components = glift.BoardComponent;
var horzBbox = glift.orientation.bbox.fromSides(point(100, 300), 300, 100);
var vertBbox = glift.orientation.bbox.fromSides(point(100, 300), 100, 300);
var squareBbox = glift.orientation.bbox.fromSides(point(100, 300), 200, 200);
Expand Down Expand Up @@ -206,7 +206,7 @@
var boxes = construct().calcVertPositioning();
var boxList = [];
boxes.map(function(key, bbox) {
ok(glift.enums.boardComponents[key] !== undefined, key);
ok(glift.BoardComponent[key] !== undefined, key);
ok(bbox.width() > 0, bbox);
boxList.push(key);
});
Expand Down Expand Up @@ -235,7 +235,7 @@
ok(boxes._second, 'second');
var boxList = [];
boxes.map(function(key, bbox) {
ok(glift.enums.boardComponents[key] !== undefined, key);
ok(glift.BoardComponent[key] !== undefined, key);
ok(bbox.width() > 0, bbox);
boxList.push(key);
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions src/glift-ui/widget_type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
goog.provide('glift.WidgetType');

/**
* The types of widgets users can create. Used to link Controllers and Options.
*
* @enum {string}
*/
glift.WidgetType = {
CORRECT_VARIATIONS_PROBLEM: 'CORRECT_VARIATIONS_PROBLEM',
EXAMPLE: 'EXAMPLE',
GAME_VIEWER: 'GAME_VIEWER',
REDUCED_GAME_VIEWER: 'REDUCED_GAME_VIEWER',
STANDARD_PROBLEM: 'STANDARD_PROBLEM',
BOARD_EDITOR: 'BOARD_EDITOR'
};
Loading

0 comments on commit c1da033

Please sign in to comment.