mirror of
				https://github.com/skishore/makemeahanzi.git
				synced 2025-10-31 10:56:39 +08:00 
			
		
		
		
	Clean up Glyphs model methods
This commit is contained in:
		| @ -2,27 +2,33 @@ | ||||
|  | ||||
| this.Glyphs = new Mongo.Collection('glyphs'); | ||||
|  | ||||
| Glyphs.findGlyphsForRadical = function(radical) { | ||||
|   if (radical) { | ||||
|     return Glyphs.find({'index.radical': radical}); | ||||
|   } | ||||
|   return Glyphs.find({'index.strokes': 0}); | ||||
| Glyphs.get = (query) => Glyphs.findOne(query); | ||||
|  | ||||
| Glyphs.getNext = (glyph) => { | ||||
|   const codepoint = glyph ? glyph.codepoint : undefined; | ||||
|   const next = Glyphs.findOne( | ||||
|       {codepoint: {$gt: codepoint}}, {sort: {codepoint: 1}}); | ||||
|   return next ? next : Glyphs.findOne({}, {sort: {codepoint: 1}}); | ||||
| } | ||||
|  | ||||
| Glyphs.get_svg_path = function(glyph) { | ||||
|   var terms = []; | ||||
|   for (var i = 0; i < glyph.path.length; i++) { | ||||
|     var segment = glyph.path[i]; | ||||
|     assert('LMQZ'.indexOf(segment.type) >= 0, segment.type); | ||||
|     terms.push(segment.type); | ||||
|     if (segment.x1 !== undefined) { | ||||
|       terms.push(segment.x1); | ||||
|       terms.push(segment.y1); | ||||
| Glyphs.getPrevious = (glyph) => { | ||||
|   const codepoint = glyph ? glyph.codepoint : undefined; | ||||
|   const previous = Glyphs.findOne( | ||||
|       {codepoint: {$lt: codepoint}}, {sort: {codepoint: -1}}); | ||||
|   return previous ? previous : Glyphs.findOne({}, {sort: {codepoint: -1}}); | ||||
| } | ||||
|     if (segment.x !== undefined) { | ||||
|       terms.push(segment.x); | ||||
|       terms.push(segment.y); | ||||
|  | ||||
| Glyphs.save = (glyph) => { | ||||
|   check(glyph.character, String); | ||||
|   assert(glyph.character.length === 1); | ||||
|   Glyphs.upsert({character: glyph.character}, glyph); | ||||
| } | ||||
|   } | ||||
|   return terms.join(' '); | ||||
|  | ||||
| // Register the methods above on the server so they are available to the client. | ||||
| if (Meteor.isServer) { | ||||
|   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
	 Shaunak Kishore
					Shaunak Kishore