Merge pull request #223 from sgsunder/add-source-handling
client: Reimplement post source functionality
This commit is contained in:
commit
abc6e018b9
6 changed files with 73 additions and 5 deletions
|
@ -58,6 +58,16 @@
|
||||||
</section>
|
</section>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
<% if (ctx.canEditPostSource) { %>
|
||||||
|
<section class='post-source'>
|
||||||
|
<%= ctx.makeTextInput({
|
||||||
|
text: 'Source',
|
||||||
|
name: 'source',
|
||||||
|
value: ctx.post.source,
|
||||||
|
}) %>
|
||||||
|
</section>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<% if (ctx.canEditPostTags) { %>
|
<% if (ctx.canEditPostTags) { %>
|
||||||
<section class='tags'>
|
<section class='tags'>
|
||||||
<%= ctx.makeTextInput({}) %>
|
<%= ctx.makeTextInput({}) %>
|
||||||
|
|
|
@ -38,6 +38,14 @@
|
||||||
<a href class='fit-both'>both</a>
|
<a href class='fit-both'>both</a>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<% if (ctx.post.source) { %>
|
||||||
|
<section class='source'>
|
||||||
|
Source: <a href='<%- ctx.post.source %>' title='<%- ctx.post.source %>'>
|
||||||
|
<%- ctx.post.prettyPrintSource() %>
|
||||||
|
</a>
|
||||||
|
</section>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<section class='search'>
|
<section class='search'>
|
||||||
Search on
|
Search on
|
||||||
<a href='http://iqdb.org/?url=<%- encodeURIComponent(ctx.post.fullContentUrl) %>'>IQDB</a> ·
|
<a href='http://iqdb.org/?url=<%- encodeURIComponent(ctx.post.fullContentUrl) %>'>IQDB</a> ·
|
||||||
|
|
|
@ -147,6 +147,9 @@ class PostMainController extends BasePostController {
|
||||||
if (e.detail.thumbnail !== undefined) {
|
if (e.detail.thumbnail !== undefined) {
|
||||||
post.newThumbnail = e.detail.thumbnail;
|
post.newThumbnail = e.detail.thumbnail;
|
||||||
}
|
}
|
||||||
|
if (e.detail.source !== undefined) {
|
||||||
|
post.source = e.detail.source;
|
||||||
|
}
|
||||||
post.save()
|
post.save()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this._view.sidebarControl.showSuccess('Post saved.');
|
this._view.sidebarControl.showSuccess('Post saved.');
|
||||||
|
|
|
@ -37,6 +37,7 @@ class PostEditSidebarControl extends events.EventTarget {
|
||||||
canEditPostFlags: api.hasPrivilege('posts:edit:flags'),
|
canEditPostFlags: api.hasPrivilege('posts:edit:flags'),
|
||||||
canEditPostContent: api.hasPrivilege('posts:edit:content'),
|
canEditPostContent: api.hasPrivilege('posts:edit:content'),
|
||||||
canEditPostThumbnail: api.hasPrivilege('posts:edit:thumbnail'),
|
canEditPostThumbnail: api.hasPrivilege('posts:edit:thumbnail'),
|
||||||
|
canEditPostSource : api.hasPrivilege('posts:edit:source'),
|
||||||
canCreateAnonymousPosts: api.hasPrivilege('posts:create:anonymous'),
|
canCreateAnonymousPosts: api.hasPrivilege('posts:create:anonymous'),
|
||||||
canDeletePosts: api.hasPrivilege('posts:delete'),
|
canDeletePosts: api.hasPrivilege('posts:delete'),
|
||||||
canFeaturePosts: api.hasPrivilege('posts:feature'),
|
canFeaturePosts: api.hasPrivilege('posts:feature'),
|
||||||
|
@ -46,7 +47,7 @@ class PostEditSidebarControl extends events.EventTarget {
|
||||||
new ExpanderControl(
|
new ExpanderControl(
|
||||||
'post-info',
|
'post-info',
|
||||||
'Basic info',
|
'Basic info',
|
||||||
this._hostNode.querySelectorAll('.safety, .relations, .flags'));
|
this._hostNode.querySelectorAll('.safety, .relations, .flags, .post-source'));
|
||||||
this._tagsExpander = new ExpanderControl(
|
this._tagsExpander = new ExpanderControl(
|
||||||
'post-tags',
|
'post-tags',
|
||||||
`Tags (${this._post.tags.length})`,
|
`Tags (${this._post.tags.length})`,
|
||||||
|
@ -349,6 +350,10 @@ class PostEditSidebarControl extends events.EventTarget {
|
||||||
thumbnail: this._newPostThumbnail !== undefined ?
|
thumbnail: this._newPostThumbnail !== undefined ?
|
||||||
this._newPostThumbnail :
|
this._newPostThumbnail :
|
||||||
undefined,
|
undefined,
|
||||||
|
|
||||||
|
source: this._sourceInputNode ?
|
||||||
|
this._sourceInputNode.value :
|
||||||
|
undefined,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -402,6 +407,10 @@ class PostEditSidebarControl extends events.EventTarget {
|
||||||
return this._formNode.querySelector('.post-thumbnail a');
|
return this._formNode.querySelector('.post-thumbnail a');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get _sourceInputNode() {
|
||||||
|
return this._formNode.querySelector('.post-source input');
|
||||||
|
}
|
||||||
|
|
||||||
get _featureLinkNode() {
|
get _featureLinkNode() {
|
||||||
return this._formNode.querySelector('.management .feature');
|
return this._formNode.querySelector('.management .feature');
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ class Post extends events.EventTarget {
|
||||||
get contentUrl() { return this._contentUrl; }
|
get contentUrl() { return this._contentUrl; }
|
||||||
get fullContentUrl() { return this._fullContentUrl; }
|
get fullContentUrl() { return this._fullContentUrl; }
|
||||||
get thumbnailUrl() { return this._thumbnailUrl; }
|
get thumbnailUrl() { return this._thumbnailUrl; }
|
||||||
|
get source() { return this._source; }
|
||||||
get canvasWidth() { return this._canvasWidth || 800; }
|
get canvasWidth() { return this._canvasWidth || 800; }
|
||||||
get canvasHeight() { return this._canvasHeight || 450; }
|
get canvasHeight() { return this._canvasHeight || 450; }
|
||||||
get fileSize() { return this._fileSize || 0; }
|
get fileSize() { return this._fileSize || 0; }
|
||||||
|
@ -57,6 +58,7 @@ class Post extends events.EventTarget {
|
||||||
set relations(value) { this._relations = value; }
|
set relations(value) { this._relations = value; }
|
||||||
set newContent(value) { this._newContent = value; }
|
set newContent(value) { this._newContent = value; }
|
||||||
set newThumbnail(value) { this._newThumbnail = value; }
|
set newThumbnail(value) { this._newThumbnail = value; }
|
||||||
|
set source(value) { this._source = value; }
|
||||||
|
|
||||||
static fromResponse(response) {
|
static fromResponse(response) {
|
||||||
const ret = new Post();
|
const ret = new Post();
|
||||||
|
@ -122,6 +124,9 @@ class Post extends events.EventTarget {
|
||||||
if (this._newThumbnail !== undefined) {
|
if (this._newThumbnail !== undefined) {
|
||||||
files.thumbnail = this._newThumbnail;
|
files.thumbnail = this._newThumbnail;
|
||||||
}
|
}
|
||||||
|
if (this._source !== this._orig._source) {
|
||||||
|
detail.source = this._source;
|
||||||
|
}
|
||||||
|
|
||||||
let apiPromise = this._id ?
|
let apiPromise = this._id ?
|
||||||
api.put(uri.formatApiLink('post', this.id), detail, files) :
|
api.put(uri.formatApiLink('post', this.id), detail, files) :
|
||||||
|
@ -266,6 +271,10 @@ class Post extends events.EventTarget {
|
||||||
Math.round(Math.random() * 1000);
|
Math.round(Math.random() * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prettyPrintSource() {
|
||||||
|
return uri.extractRootDomain(this._source);
|
||||||
|
}
|
||||||
|
|
||||||
_updateFromResponse(response) {
|
_updateFromResponse(response) {
|
||||||
const map = () => ({
|
const map = () => ({
|
||||||
_version: response.version,
|
_version: response.version,
|
||||||
|
@ -278,6 +287,7 @@ class Post extends events.EventTarget {
|
||||||
_contentUrl: response.contentUrl,
|
_contentUrl: response.contentUrl,
|
||||||
_fullContentUrl: new URL(response.contentUrl, document.getElementsByTagName('base')[0].href).href,
|
_fullContentUrl: new URL(response.contentUrl, document.getElementsByTagName('base')[0].href).href,
|
||||||
_thumbnailUrl: response.thumbnailUrl,
|
_thumbnailUrl: response.thumbnailUrl,
|
||||||
|
_source: response.source,
|
||||||
_canvasWidth: response.canvasWidth,
|
_canvasWidth: response.canvasWidth,
|
||||||
_canvasHeight: response.canvasHeight,
|
_canvasHeight: response.canvasHeight,
|
||||||
_fileSize: response.fileSize,
|
_fileSize: response.fileSize,
|
||||||
|
|
|
@ -54,9 +54,37 @@ function formatClientLink(...values) {
|
||||||
return parts.join('/');
|
return parts.join('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractHostname(url) {
|
||||||
|
// https://stackoverflow.com/a/23945027
|
||||||
|
return url
|
||||||
|
.split('/')[url.indexOf("//") > -1 ? 2 : 0]
|
||||||
|
.split(':')[0]
|
||||||
|
.split('?')[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractRootDomain(url) {
|
||||||
|
// https://stackoverflow.com/a/23945027
|
||||||
|
let domain = extractHostname(url);
|
||||||
|
let splitArr = domain.split('.');
|
||||||
|
let arrLen = splitArr.length;
|
||||||
|
|
||||||
|
//if there is a subdomain
|
||||||
|
if (arrLen > 2) {
|
||||||
|
domain = splitArr[arrLen - 2] + '.' + splitArr[arrLen - 1];
|
||||||
|
//check to see if it's using a Country Code Top Level Domain (ccTLD) (i.e. ".me.uk")
|
||||||
|
if (splitArr[arrLen - 2].length == 2 && splitArr[arrLen - 1].length == 2) {
|
||||||
|
//this is using a ccTLD
|
||||||
|
domain = splitArr[arrLen - 3] + '.' + domain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
formatClientLink: formatClientLink,
|
formatClientLink: formatClientLink,
|
||||||
formatApiLink: formatApiLink,
|
formatApiLink: formatApiLink,
|
||||||
escapeParam: escapeParam,
|
escapeParam: escapeParam,
|
||||||
unescapeParam: unescapeParam,
|
unescapeParam: unescapeParam,
|
||||||
|
extractHostname: extractHostname,
|
||||||
|
extractRootDomain: extractRootDomain,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue