mirror of
https://github.com/skishore/makemeahanzi.git
synced 2025-10-30 02:18:16 +08:00
Clean up Glyphs model methods
This commit is contained in:
@ -2,27 +2,33 @@
|
|||||||
|
|
||||||
this.Glyphs = new Mongo.Collection('glyphs');
|
this.Glyphs = new Mongo.Collection('glyphs');
|
||||||
|
|
||||||
Glyphs.findGlyphsForRadical = function(radical) {
|
Glyphs.get = (query) => Glyphs.findOne(query);
|
||||||
if (radical) {
|
|
||||||
return Glyphs.find({'index.radical': radical});
|
Glyphs.getNext = (glyph) => {
|
||||||
}
|
const codepoint = glyph ? glyph.codepoint : undefined;
|
||||||
return Glyphs.find({'index.strokes': 0});
|
const next = Glyphs.findOne(
|
||||||
|
{codepoint: {$gt: codepoint}}, {sort: {codepoint: 1}});
|
||||||
|
return next ? next : Glyphs.findOne({}, {sort: {codepoint: 1}});
|
||||||
}
|
}
|
||||||
|
|
||||||
Glyphs.get_svg_path = function(glyph) {
|
Glyphs.getPrevious = (glyph) => {
|
||||||
var terms = [];
|
const codepoint = glyph ? glyph.codepoint : undefined;
|
||||||
for (var i = 0; i < glyph.path.length; i++) {
|
const previous = Glyphs.findOne(
|
||||||
var segment = glyph.path[i];
|
{codepoint: {$lt: codepoint}}, {sort: {codepoint: -1}});
|
||||||
assert('LMQZ'.indexOf(segment.type) >= 0, segment.type);
|
return previous ? previous : Glyphs.findOne({}, {sort: {codepoint: -1}});
|
||||||
terms.push(segment.type);
|
}
|
||||||
if (segment.x1 !== undefined) {
|
|
||||||
terms.push(segment.x1);
|
Glyphs.save = (glyph) => {
|
||||||
terms.push(segment.y1);
|
check(glyph.character, String);
|
||||||
}
|
assert(glyph.character.length === 1);
|
||||||
if (segment.x !== undefined) {
|
Glyphs.upsert({character: glyph.character}, glyph);
|
||||||
terms.push(segment.x);
|
}
|
||||||
terms.push(segment.y);
|
|
||||||
}
|
// Register the methods above on the server so they are available to the client.
|
||||||
}
|
if (Meteor.isServer) {
|
||||||
return terms.join(' ');
|
const methods = {};
|
||||||
|
const method_names = ['get', 'getNext', 'getPrevious', 'save'];
|
||||||
|
method_names.map((name) => methods[`${name}Glyph`] = Glyphs[name]);
|
||||||
|
methods.saveGlyphs = (glyphs) => glyphs.map(Glyphs.save);
|
||||||
|
Meteor.methods(methods);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,56 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
function save_glyph(glyph) {
|
|
||||||
check(glyph.name, String);
|
|
||||||
var saved_glyph = _.extend({}, glyph);
|
|
||||||
if (saved_glyph.render !== undefined) {
|
|
||||||
saved_glyph.derived = {
|
|
||||||
errors: saved_glyph.render.log.filter(function(pair) {
|
|
||||||
return pair[0] !== 'success';
|
|
||||||
}),
|
|
||||||
strokes: saved_glyph.render.strokes,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
delete saved_glyph.render;
|
|
||||||
Glyphs.upsert({name: glyph.name}, saved_glyph);
|
|
||||||
return glyph;
|
|
||||||
}
|
|
||||||
|
|
||||||
Meteor.methods({
|
|
||||||
get_glyph: function(character) {
|
|
||||||
return Glyphs.findOne({character: character});
|
|
||||||
},
|
|
||||||
get_next_glyph: function(glyph) {
|
|
||||||
var name = glyph ? glyph.name : undefined;
|
|
||||||
var next = Glyphs.findOne({name: {$gt: name}}, {sort: {name: 1}});
|
|
||||||
return next ? next : Glyphs.findOne({}, {sort: {name: 1}});
|
|
||||||
},
|
|
||||||
get_next_glyph_skip_verified: function(glyph) {
|
|
||||||
var name = glyph ? glyph.name : undefined;
|
|
||||||
var next = Glyphs.findOne(
|
|
||||||
{name: {$gt: name}, 'manual.verified': {$ne: true}}, {sort: {name: 1}});
|
|
||||||
return next ? next : Glyphs.findOne(
|
|
||||||
{'manual.verified': {$ne: true}}, {sort: {name: 1}});
|
|
||||||
},
|
|
||||||
get_previous_glyph: function(glyph) {
|
|
||||||
var name = glyph ? glyph.name : undefined;
|
|
||||||
var prev = Glyphs.findOne({name: {$lt: name}}, {sort: {name: -1}});
|
|
||||||
return prev ? prev : Glyphs.findOne({}, {sort: {name: -1}});
|
|
||||||
},
|
|
||||||
get_previous_glyph_skip_verified: function(glyph) {
|
|
||||||
var name = glyph ? glyph.name : undefined;
|
|
||||||
var prev = Glyphs.findOne(
|
|
||||||
{name: {$lt: name}, 'manual.verified': {$ne: true}}, {sort: {name: -1}});
|
|
||||||
return prev ? prev : Glyphs.findOne(
|
|
||||||
{'manual.verified': {$ne: true}}, {sort: {name: -1}});
|
|
||||||
},
|
|
||||||
get_fraction_verified: function() {
|
|
||||||
return Glyphs.find({'manual.verified': true}).count()/Glyphs.find().count();
|
|
||||||
},
|
|
||||||
save_glyph: save_glyph,
|
|
||||||
save_glyphs: function(glyphs) {
|
|
||||||
for (var i = 0; i < glyphs.length; i++) {
|
|
||||||
save_glyph(glyphs[i]);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user