Skip to content

Commit

Permalink
Merge pull request #67 from tomaszrondio/master
Browse files Browse the repository at this point in the history
feature: new approach to targeted publishing preview
  • Loading branch information
takeit authored Nov 6, 2018
2 parents a636740 + a4b5e01 commit 2dfc89c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion client/controllers/WebPublisherContentListsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export function WebPublisherContentListsController($scope, publisher, modal, $ti
});
}

publisher.queryRoutes().then((routes) => {
publisher.queryRoutes({type: 'collection'}).then((routes) => {
$scope.routes = routes;
if ($scope.newList.filters.route && $scope.newList.filters.route.length > 0) {
routes.forEach((item) => {
Expand Down
66 changes: 32 additions & 34 deletions client/extensions/targetedPublishing/TargetedPublishing.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,11 @@ export class TargetedPublishing extends React.Component {
code: item.qcode
};
});
let filteredItem = {
guid: item.guid,
language: item.language,
body_html: item.body_html,
byline: item.byline,
keywords: item.keywords,
priority: item.priority,
urgency: item.urgency,
headline: item.headline,
description_html: item.abstract,
pubstatus: item.pubstatus,
authors: item.authors,
extra: item.extra,
source: item.source,
service: service
};

filteredItem = _(filteredItem).omitBy(_.isNil).omitBy(_.isEmpty).value();

this.state = {
config: config,
session: session,
item: filteredItem,
item: null,
apiUrl: `${protocol}://${subdomain}${domainName}/api/v1/`,
apiHeader: null,
sites: [],
Expand All @@ -55,6 +37,36 @@ export class TargetedPublishing extends React.Component {
};
}

componentDidMount() {
const {api, item, urls} = this.props;

api.query('subscribers')
.then((res) => {
let subscriber_id = (res['_items'])[0] ? (res['_items'])[0]._id : null;
let formatterUrl = urls.item('format-document-for-preview')
+ `?subscriber_id=${subscriber_id}&formatter=ninjs&document_id=${item._id}`;

fetch(formatterUrl).then((response) => response.text()
.then((responseText) => {
let json = JSON.parse(responseText);
this.setState({item: json});
this.prepare();
}));
});
}

prepare() {
this.authorize()
.then((res) => {
this.setState(
{apiHeader: {Authorization: 'Basic ' + res.data.token.api_key}},
() => {
this.evaluate();
this.getSites();
});
});
}

authorize() {
return axios.post(this.state.apiUrl + 'auth/superdesk/', {auth_superdesk: {session_id: this.state.session.sessionId, token: this.state.session.token}});
}
Expand Down Expand Up @@ -110,20 +122,6 @@ export class TargetedPublishing extends React.Component {
this.evaluate();
}

componentDidMount() {
this.authorize()
.then((res) => {
this.setState(
{apiHeader: {Authorization: 'Basic ' + res.data.token.api_key}},
() => {
this.evaluate();
this.getSites();
});
});
}



render() {
let styles = {
alert: {
Expand Down Expand Up @@ -208,7 +206,7 @@ export class TargetedPublishing extends React.Component {

if (remainingSites.length && !this.state.loading) {
addButton = (
<button class="btn btn--primary btn--icon-only-circle" onClick={this.addButtonHandler.bind(this)}>
<button className="btn btn--primary btn--icon-only-circle" onClick={this.addButtonHandler.bind(this)}>
<i className="icon-plus-large"></i>
</button>
);
Expand Down
4 changes: 3 additions & 1 deletion client/views/content-lists/content-list-automatic.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ <h3 class="side-panel__heading side-panel__heading--big">Automatic List Criteria
data-label="Routes"
data-items="routes"
data-field="name"
data-freetext="false" >
data-freetext="false"
data-max-results-to-show=20 >
<tags-input
ng-model="model"
add-from-autocomplete-only="{{items ? !freetext : false}}"
show-button="{{!!items}}"
display-property="{{field}}"
use-strings="{{!field}}"
data-max-results-to-show=20
></tags-input>
</sd-tag-input>
</div>
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export default angular.module('superdesk-publisher', [
.factory('publisher', services.PublisherFactory)
.factory('pubapi', services.PubAPIFactory)

.run(['extensionPoints', 'session', 'config', '$templateCache', (extensionPoints, session, config, $templateCache) => {
.run(['extensionPoints', 'session', 'config', '$templateCache', 'urls', 'api', (extensionPoints, session, config, $templateCache, urls, api) => {
cacheIncludedTemplates($templateCache);
extensionPoints.register('authoring:publish', TargetedPublishing, {session: session, config: config}, ['item']);
extensionPoints.register('authoring:publish', TargetedPublishing, {session: session, config: config, urls: urls, api: api}, ['item']);
}])

.config(['superdeskProvider', 'workspaceMenuProvider', function(superdesk, workspaceMenuProvider) {
Expand Down

0 comments on commit 2dfc89c

Please sign in to comment.