cleaning up drafty and UI fixes in permissions editing

This commit is contained in:
or-else
2017-09-02 15:57:03 -07:00
parent d34f51a9d0
commit 73b2a85eea
2 changed files with 40 additions and 29 deletions
+17 -17
View File
@@ -32,7 +32,7 @@ Sample JSON representation of the text above:
{ "at":144, "len":8, "key":2 },{ "at":159, "len":8, "key":3 },{ "tp":"BR", "len":1, "at":179 },
{ "at":187, "len":8, "key":3 },{ "tp":"BR", "len":1, "at":195 }
],
"refs": [
"ent": [
{ "tp":"LN", "data":{ "url":"https://www.example.com/abc#fragment" } },
{ "tp":"LN", "data":{ "url":"http://www.tinode.co" } },
{ "tp":"MN", "data":{ "val":"mention" } },
@@ -283,14 +283,14 @@ Sample JSON representation of the text above:
function extractEntities(line) {
var match;
var extracted = [];
ENTITY_TYPES.map(function(ent) {
while ((match = ent.re.exec(line)) !== null) {
ENTITY_TYPES.map(function(entity) {
while ((match = entity.re.exec(line)) !== null) {
extracted.push({
offset: match['index'],
len: match[0].length,
unique: match[0],
data: ent.pack(match[0]),
type: ent.name});
data: entity.pack(match[0]),
type: entity.name});
}
});
@@ -391,14 +391,14 @@ Sample JSON representation of the text above:
var ranges = [];
for (var i in entities) {
// {offset: match['index'], unique: match[0], len: match[0].length, data: ent.packer(), type: ent.name}
var ent = entities[i];
var index = entityIndex[ent.unique];
var entity = entities[i];
var index = entityIndex[entity.unique];
if (!index) {
index = entityMap.length;
entityIndex[ent.unique] = index;
entityMap.push({tp: ent.type, data: ent.data});
entityIndex[entity.unique] = index;
entityMap.push({tp: entity.type, data: entity.data});
}
ranges.push({at: ent.offset, len: ent.len, key: index});
ranges.push({at: entity.offset, len: entity.len, key: index});
}
block.ent = ranges;
}
@@ -437,7 +437,7 @@ Sample JSON representation of the text above:
}
if (entityMap.length > 0) {
result.refs = entityMap;
result.ent = entityMap;
}
}
return result;
@@ -454,7 +454,7 @@ Sample JSON representation of the text above:
* @return HTML-representation of content
*/
unsafeToHTML: function(content) {
var {txt, fmt, refs} = content;
var {txt, fmt, ent} = content;
var markup = [];
if (fmt) {
@@ -462,7 +462,7 @@ Sample JSON representation of the text above:
var range = fmt[i];
var tp = range.tp, data;
if (!tp) {
var entity = refs[range.key];
var entity = ent[range.key];
if (entity) {
tp = entity.tp;
data = entity.data;
@@ -499,7 +499,7 @@ Sample JSON representation of the text above:
* @return {Object} context
*/
format: function(content, formatter, context) {
var {txt, fmt, refs} = content;
var {txt, fmt, ent} = content;
if (!fmt) {
return [txt];
@@ -521,8 +521,8 @@ Sample JSON representation of the text above:
var data;
var tp = s.tp;
if (s.key + 1 > 0) {
data = refs[s.key].data;
tp = refs[s.key].tp;
data = ent[s.key].data;
tp = ent[s.key].tp;
}
return {tp: tp, data: data, at: s.at, len: s.len};
});
@@ -546,7 +546,7 @@ Sample JSON representation of the text above:
* @returns true is content is plain text, false otherwise.
*/
isPlainText: function(content, noLineBreaks) {
return !(content.fmt || content.refs);
return !(content.fmt || content.ent);
},
/**
+23 -12
View File
@@ -385,7 +385,7 @@
var PermissionsEditor = React.createClass({
getInitialState: function() {
return {
mode: this.props.mode
mode: (this.props.mode || "").replace("N", "")
};
},
@@ -427,7 +427,7 @@
};
var skip = this.props.skip || "";
var mode = (this.state.mode || "").replace("N", "");
var mode = this.state.mode;
var compare = (this.props.compare || "").replace("N", "");
var items = [];
for (var i=0; i<all.length; i++) {
@@ -1715,6 +1715,7 @@
var acs = topic.getAccessMode();
this.setState({
owner: acs && acs.isOwner(),
admin: acs && acs.isAdmin(),
sharer: acs && (acs.isAdmin() || acs.isSharer()),
muted: acs && acs.isMuted(),
@@ -1822,7 +1823,7 @@
toSkip = 'O';
break;
case 'anon':
toEdit = this.state.auth;
toEdit = this.state.anon;
toSkip = 'O';
break;
default:
@@ -1955,18 +1956,28 @@
</div>
</div>
}
{this.state.auth || this.state.anon ?
{this.state.sharer && (this.state.auth || this.state.anon) ?
<div>
<div><label className="small">Default access mode:</label></div>
<div className="quoted">
<div>Auth: <tt className="clickable"
onClick={this.handleLaunchPermissionsEditor.bind(this, 'auth')}>
{this.state.auth}
</tt></div>
<div>Anon: <tt className="clickable"
onClick={this.handleLaunchPermissionsEditor.bind(this, 'anon')}>
{this.state.anon}
</tt></div>
<div>Auth: {this.state.admin ?
<tt className="clickable"
onClick={this.handleLaunchPermissionsEditor.bind(this, 'auth')}>
{this.state.auth}
</tt>
:
<tt>{this.state.auth}</tt>
}
</div>
<div>Anon: {this.state.admin ?
<tt className="clickable"
onClick={this.handleLaunchPermissionsEditor.bind(this, 'anon')}>
{this.state.anon}
</tt>
:
<tt>{this.state.anon}</tt>
}
</div>
</div>
</div>
: