Add a parameter 'lineBreaks' to getTextByMode

This commit is contained in:
Tobias Hößl 2017-04-12 20:17:02 +02:00
parent b7fdbc88d6
commit a558e190ea
3 changed files with 29 additions and 19 deletions

View File

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

View File

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

View File

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