mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
added isTranslationPatch method to patches
This commit is contained in:
parent
fce9f0031b
commit
bb1c07570d
4 changed files with 37 additions and 12 deletions
|
@ -11,7 +11,8 @@ module.exports.expandDelta = (delta, left, schema) ->
|
|||
flattenedDeltas = flattenDelta(delta)
|
||||
(expandFlattenedDelta(fd, left, schema) for fd in flattenedDeltas)
|
||||
|
||||
flattenDelta = (delta, dataPath=null, deltaPath=null) ->
|
||||
|
||||
module.exports.flattenDelta = flattenDelta = (delta, dataPath=null, deltaPath=null) ->
|
||||
# takes a single jsondiffpatch delta and returns an array of objects with
|
||||
return [] unless delta
|
||||
dataPath ?= []
|
||||
|
@ -26,7 +27,8 @@ flattenDelta = (delta, dataPath=null, deltaPath=null) ->
|
|||
results = results.concat flattenDelta(
|
||||
childDelta, dataPath.concat([dataIndex]), deltaPath.concat([deltaIndex]))
|
||||
results
|
||||
pandFlattenedDelta = (delta, left, schema) ->
|
||||
|
||||
expandFlattenedDelta = (delta, left, schema) ->
|
||||
# takes a single flattened delta and converts into an object that can be
|
||||
# easily formatted into something human readable.
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
CocoView = require 'views/kinds/CocoView'
|
||||
template = require 'templates/editor/delta'
|
||||
deltasLib = require 'lib/deltas'
|
||||
window.delta = deltasLib
|
||||
|
||||
TEXTDIFF_OPTIONS =
|
||||
baseTextName: "Old"
|
||||
|
|
|
@ -47,14 +47,12 @@ PatchSchema.pre 'save', (next) ->
|
|||
document.save (err) -> next(err)
|
||||
|
||||
PatchSchema.methods.isTranslationPatch = ->
|
||||
console.log @get 'delta'
|
||||
expanded = deltas.expandDelta @get('delta')
|
||||
console.log 'expanded'
|
||||
_.some expanded, (delta) -> 'i18n' in expanded.dataPath
|
||||
expanded = deltas.flattenDelta @get('delta')
|
||||
_.some expanded, (delta) -> 'i18n' in delta.dataPath
|
||||
|
||||
PatchSchema.methods.isMiscPatch = ->
|
||||
expanded = deltas.expandDelta @get 'delta'
|
||||
_.some expanded, (delta) -> 'i18n' not in expanded.dataPath
|
||||
expanded = deltas.flattenDelta @get('delta')
|
||||
_.some expanded, (delta) -> 'i18n' not in delta.dataPath
|
||||
|
||||
# Keep track of when a patch is pending. Accepted patches can be rejected still.
|
||||
PatchSchema.path('status').set (newVal) ->
|
||||
|
|
|
@ -2,13 +2,37 @@ require '../common'
|
|||
|
||||
describe 'schema methods', ->
|
||||
patch = new Patch
|
||||
commitMessage: 'Accept this patch!'
|
||||
editPath: '/who/knows/yes'
|
||||
target:
|
||||
id:null
|
||||
collection: 'article'
|
||||
delta:
|
||||
scripts: 0: i18n: 'aaahw yeahh'
|
||||
_t: 'a'
|
||||
"scripts":
|
||||
"0":
|
||||
"noteChain":
|
||||
"1":
|
||||
"sprites":
|
||||
"0":
|
||||
"say":
|
||||
"i18n":
|
||||
"nl-BE": [ "text": "aaahw yeahh" ]
|
||||
"_t": "a"
|
||||
"_t": "a"
|
||||
"_t": "a"
|
||||
"thangs":
|
||||
"111": [
|
||||
"components": [
|
||||
"config": {
|
||||
"stateless": true
|
||||
}
|
||||
]
|
||||
]
|
||||
"_t": "a"
|
||||
|
||||
it 'is translation patch', ->
|
||||
expect(patch.isTranslationPatch()).toBeTruthy()
|
||||
patch.set 'delta.i18n', undefined
|
||||
patch.set 'delta.scripts', undefined
|
||||
expect(patch.isTranslationPatch()).toBeFalsy()
|
||||
|
||||
it 'is miscellaneous patch', ->
|
||||
|
|
Loading…
Reference in a new issue