mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-24 13:34:08 -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)
|
flattenedDeltas = flattenDelta(delta)
|
||||||
(expandFlattenedDelta(fd, left, schema) for fd in flattenedDeltas)
|
(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
|
# takes a single jsondiffpatch delta and returns an array of objects with
|
||||||
return [] unless delta
|
return [] unless delta
|
||||||
dataPath ?= []
|
dataPath ?= []
|
||||||
|
@ -26,7 +27,8 @@ flattenDelta = (delta, dataPath=null, deltaPath=null) ->
|
||||||
results = results.concat flattenDelta(
|
results = results.concat flattenDelta(
|
||||||
childDelta, dataPath.concat([dataIndex]), deltaPath.concat([deltaIndex]))
|
childDelta, dataPath.concat([dataIndex]), deltaPath.concat([deltaIndex]))
|
||||||
results
|
results
|
||||||
pandFlattenedDelta = (delta, left, schema) ->
|
|
||||||
|
expandFlattenedDelta = (delta, left, schema) ->
|
||||||
# takes a single flattened delta and converts into an object that can be
|
# takes a single flattened delta and converts into an object that can be
|
||||||
# easily formatted into something human readable.
|
# easily formatted into something human readable.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
CocoView = require 'views/kinds/CocoView'
|
CocoView = require 'views/kinds/CocoView'
|
||||||
template = require 'templates/editor/delta'
|
template = require 'templates/editor/delta'
|
||||||
deltasLib = require 'lib/deltas'
|
deltasLib = require 'lib/deltas'
|
||||||
|
window.delta = deltasLib
|
||||||
|
|
||||||
TEXTDIFF_OPTIONS =
|
TEXTDIFF_OPTIONS =
|
||||||
baseTextName: "Old"
|
baseTextName: "Old"
|
||||||
|
@ -112,4 +113,4 @@ module.exports = class DeltaView extends CocoView
|
||||||
delta = @model.getDelta()
|
delta = @model.getDelta()
|
||||||
delta = deltasLib.pruneConflictsFromDelta delta, @conflicts if @conflicts
|
delta = deltasLib.pruneConflictsFromDelta delta, @conflicts if @conflicts
|
||||||
delta = deltasLib.pruneExpandedDeltasFromDelta delta, @skippedDeltas if @skippedDeltas
|
delta = deltasLib.pruneExpandedDeltasFromDelta delta, @skippedDeltas if @skippedDeltas
|
||||||
delta
|
delta
|
||||||
|
|
|
@ -47,14 +47,12 @@ PatchSchema.pre 'save', (next) ->
|
||||||
document.save (err) -> next(err)
|
document.save (err) -> next(err)
|
||||||
|
|
||||||
PatchSchema.methods.isTranslationPatch = ->
|
PatchSchema.methods.isTranslationPatch = ->
|
||||||
console.log @get 'delta'
|
expanded = deltas.flattenDelta @get('delta')
|
||||||
expanded = deltas.expandDelta @get('delta')
|
_.some expanded, (delta) -> 'i18n' in delta.dataPath
|
||||||
console.log 'expanded'
|
|
||||||
_.some expanded, (delta) -> 'i18n' in expanded.dataPath
|
|
||||||
|
|
||||||
PatchSchema.methods.isMiscPatch = ->
|
PatchSchema.methods.isMiscPatch = ->
|
||||||
expanded = deltas.expandDelta @get 'delta'
|
expanded = deltas.flattenDelta @get('delta')
|
||||||
_.some expanded, (delta) -> 'i18n' not in expanded.dataPath
|
_.some expanded, (delta) -> 'i18n' not in delta.dataPath
|
||||||
|
|
||||||
# Keep track of when a patch is pending. Accepted patches can be rejected still.
|
# Keep track of when a patch is pending. Accepted patches can be rejected still.
|
||||||
PatchSchema.path('status').set (newVal) ->
|
PatchSchema.path('status').set (newVal) ->
|
||||||
|
|
|
@ -2,13 +2,37 @@ require '../common'
|
||||||
|
|
||||||
describe 'schema methods', ->
|
describe 'schema methods', ->
|
||||||
patch = new Patch
|
patch = new Patch
|
||||||
|
commitMessage: 'Accept this patch!'
|
||||||
|
editPath: '/who/knows/yes'
|
||||||
|
target:
|
||||||
|
id:null
|
||||||
|
collection: 'article'
|
||||||
delta:
|
delta:
|
||||||
scripts: 0: i18n: 'aaahw yeahh'
|
"scripts":
|
||||||
_t: 'a'
|
"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', ->
|
it 'is translation patch', ->
|
||||||
expect(patch.isTranslationPatch()).toBeTruthy()
|
expect(patch.isTranslationPatch()).toBeTruthy()
|
||||||
patch.set 'delta.i18n', undefined
|
patch.set 'delta.scripts', undefined
|
||||||
expect(patch.isTranslationPatch()).toBeFalsy()
|
expect(patch.isTranslationPatch()).toBeFalsy()
|
||||||
|
|
||||||
it 'is miscellaneous patch', ->
|
it 'is miscellaneous patch', ->
|
||||||
|
|
Loading…
Reference in a new issue