-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add (sub)category class (+ superclass) to remove hardcoded categories…
… in the (non-view) JavaScript.
- Loading branch information
Showing
8 changed files
with
124 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Category extends CategoryEnum { | ||
|
||
static _categories = []; | ||
|
||
static NOTE = new Category('note', '#44ee11'); //green | ||
static CONTENT = new Category('content', '#eeee00'); //yellow | ||
static PRESENTATION = new Category('presentation', '#ff9933'); //orange | ||
static MISTAKE = new Category('mistake', '#ff0000'); //red | ||
|
||
constructor(name, color) { | ||
super(name); | ||
this.color = color; | ||
Category._categories.push(this); | ||
} | ||
|
||
static getByName(name) { | ||
return super.getByName(name, Category._categories); | ||
} | ||
|
||
static all() { | ||
return super.all(Category._categories); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class CategoryEnum { | ||
|
||
constructor(name) { | ||
this.name = name; | ||
} | ||
|
||
/* | ||
* Returns the correct locale for the given category. | ||
* This method will only work if the given thyme player | ||
* has a div-tag with the id "annotation-locales" which | ||
* includes the name of the categories as data sets, e.g. | ||
* data-note="<%= t(...) %>". | ||
*/ | ||
locale() { | ||
return document.getElementById('annotation-locales').dataset[this.name]; | ||
} | ||
|
||
/* | ||
* Return the object with the given name in the given array. | ||
* | ||
* Override in subclasses. | ||
*/ | ||
static getByName(name, array) { | ||
for (let a of array) { | ||
if (a.name === name) { | ||
return a; | ||
} | ||
} | ||
} | ||
|
||
/* | ||
* Returns an array with all objects of this enum. | ||
* | ||
* Override in subclasses. | ||
*/ | ||
static all(array) { | ||
return array.slice(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Subcategory extends CategoryEnum { | ||
|
||
static _subcategories = []; // do not manipulate this array outside of this class! | ||
|
||
static DEFINITION = new Subcategory('definition'); | ||
static ARGUMENT = new Subcategory('argument'); | ||
static STRATEGY = new Subcategory('strategy'); | ||
|
||
constructor(name) { | ||
super(name); | ||
Subcategory._subcategories.push(this); | ||
} | ||
|
||
static getByName(name) { | ||
return super.getByName(name, Subcategory._subcategories); | ||
} | ||
|
||
static all() { | ||
return super.all(Subcategory._subcategories); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters