Merge pull request #3198 from CatoTH/Issue3183-getTextNoLineBreaks

Add a parameter 'lineBreaks' to getTextByMode
This commit is contained in:
Norman Jäckel 2017-04-19 14:45:24 +02:00 committed by GitHub
commit 8380e97f93
3 changed files with 29 additions and 19 deletions

View File

@ -291,7 +291,7 @@ angular.module('OpenSlidesApp.motions', [
}
return html;
},
_getTextWithChangeRecommendations: function (versionId, highlight, statusCompareCb) {
_getTextWithChangeRecommendations: function (versionId, highlight, lineBreaks, statusCompareCb) {
var lineLength = Config.get('motions_line_length').value,
html = this.getVersion(versionId).text,
changes = this.getChangeRecommendations(versionId, 'DESC');
@ -299,33 +299,45 @@ angular.module('OpenSlidesApp.motions', [
for (var i = 0; i < changes.length; i++) {
var change = changes[i];
if (typeof statusCompareCb === 'undefined' || statusCompareCb(change.rejected)) {
html = lineNumberingService.insertLineNumbers(html, lineLength);
html = lineNumberingService.insertLineNumbers(html, lineLength, null, null, 1);
html = diffService.replaceLines(html, change.text, change.line_from, change.line_to);
}
}
return lineNumberingService.insertLineNumbers(html, lineLength, highlight);
if (lineBreaks) {
html = lineNumberingService.insertLineNumbers(html, lineLength, highlight, null, 1);
}
return html;
},
getTextWithAllChangeRecommendations: function (versionId, highlight) {
return this._getTextWithChangeRecommendations(versionId, highlight, function() {
getTextWithAllChangeRecommendations: function (versionId, highlight, lineBreaks) {
return this._getTextWithChangeRecommendations(versionId, highlight, lineBreaks, function() {
return true;
});
},
getTextWithoutRejectedChangeRecommendations: function (versionId, highlight) {
return this._getTextWithChangeRecommendations(versionId, highlight, function(rejected) {
getTextWithoutRejectedChangeRecommendations: function (versionId, highlight, lineBreaks) {
return this._getTextWithChangeRecommendations(versionId, highlight, lineBreaks, function(rejected) {
return !rejected;
});
},
getTextByMode: function(mode, versionId, highlight) {
getTextByMode: function(mode, versionId, highlight, lineBreaks) {
/*
* @param mode ['original', 'diff', 'changed', 'agreed']
* @param versionId [if undefined, active_version will be used]
* @param highlight [the line number to highlight]
* @param lineBreaks [if line numbers / breaks should be included in the result]
*/
lineBreaks = (lineBreaks === undefined ? true : lineBreaks);
var text;
switch (mode) {
case 'original':
if (lineBreaks) {
text = this.getTextWithLineBreaks(versionId, highlight);
} else {
text = this.getVersion(versionId).text;
}
break;
case 'diff':
var changes = this.getChangeRecommendations(versionId, 'ASC');
@ -335,12 +347,16 @@ angular.module('OpenSlidesApp.motions', [
text += changes[i].getDiff(this, versionId, highlight);
}
text += this.getTextRemainderAfterLastChangeRecommendation(versionId, changes);
if (!lineBreaks) {
text = lineNumberingService.stripLineNumbers(text);
}
break;
case 'changed':
text = this.getTextWithAllChangeRecommendations(versionId, highlight);
text = this.getTextWithAllChangeRecommendations(versionId, highlight, lineBreaks);
break;
case 'agreed':
text = this.getTextWithoutRejectedChangeRecommendations(versionId, highlight);
text = this.getTextWithoutRejectedChangeRecommendations(versionId, highlight, lineBreaks);
break;
}
return text;

View File

@ -34,10 +34,7 @@ angular.module('OpenSlidesApp.motions.csv', [])
makeHeaderline()
];
_.forEach(motions, function (motion) {
// TODO: Add a parameter 'noLineBreaks' to 'getTextByMode'. Currently linenumbers are
// removed directy after inserting --> not necessary. (See issue 3183)
var text = motion.getTextByMode(params.changeRecommendationMode);
text = lineNumberingService.stripLineNumbers(text);
var text = motion.getTextByMode(params.changeRecommendationMode, null, null, false);
var row = [];
row.push('"' + motion.identifier !== null ? motion.identifier : '' + '"');
row.push('"' + motion.getTitle() + '"');

View File

@ -80,10 +80,7 @@ angular.module('OpenSlidesApp.motions.docx', [])
status_translation = gettextCatalog.getString('Status'),
reason_translation = gettextCatalog.getString('Reason'),
data = _.map(motions, function (motion) {
// TODO: Add a parameter 'noLineBreaks' to 'getTextByMode'. Currently linenumbers are
// removed directy after inserting --> not necessary. (See issue #3183)
var text = motion.getTextByMode(params.changeRecommendationMode);
text = lineNumberingService.stripLineNumbers(text);
var text = motion.getTextByMode(params.changeRecommendationMode, null, null, false);
var reason = params.includeReason ? motion.getReason() : '';
return {
motion_translation: translation,