Skip to content

Commit

Permalink
Merge pull request #367 from superdesk/release/2.8
Browse files Browse the repository at this point in the history
Release/2.8 changes to develop
  • Loading branch information
IvanJelicSF authored Dec 25, 2024
2 parents ea6a2df + e2efd84 commit 2f4dfc0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 18 deletions.
16 changes: 9 additions & 7 deletions client/components/ContentLists/Manual/ArticleItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ const ArticleItem = ({
</div>
<div className="sd-list-item__row">
<span className="sd-overflow-ellipsis sd-list-item--element-grow">
<time
title={moment(item.published_at).format()}
sd-tooltip={moment(item.published_at).format("HH:mm")}
flow="right"
>
{moment(item.published_at).format("YYYY-MM-DD")}
</time>
{item.published_at &&
<time
title={moment(item.published_at).format()}
sd-tooltip={moment(item.published_at).format("HH:mm")}
flow="right"
>
{moment(item.published_at).format("YYYY-MM-DD")}
</time>
}
{item.updated_at && item.updated_at !== item.published_at ? (
<time
title={moment(item.updated_at).format()}
Expand Down
57 changes: 48 additions & 9 deletions client/components/ContentLists/Manual/Manual.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Manual extends React.Component {

if (listEl.scrollHeight - el.scrollTop - el.clientHeight < 100) {
if (list === "articles") {
this.state.source && this.state.source.id === 'superdesk' ?
this.state.source && (this.state.source.id === 'scheduled' || this.state.source.id === 'in_progress') ?
this._querySuperdeskArticles() :
this._queryArticles();
} else {
Expand Down Expand Up @@ -250,7 +250,7 @@ class Manual extends React.Component {
});
};

_querySuperdeskArticles = (filter, reset = false) => {
_querySuperdeskArticles = (filter = this.state.source.id, reset = false) => {
// Get Superdesk API instance
const superedeskApi = window['extensionsApiInstances']['publisher-extension'];

Expand Down Expand Up @@ -324,15 +324,42 @@ class Manual extends React.Component {
format_type: "NINJSFormatter"
},
}).then((response) => {
const ninjs = this.props.publisher.publishSuperdeskArticle(response.export[item_id]).then(() => {
this.props.publisher.getArticleByCode(item_id).then((res) => {
resolve(res);
});
const ninjs = this.props.publisher.publishSuperdeskArticle('new', response.export[item_id]).then(async (response) => {
try {
const article_id = await this.attemptFetch(10, item_id);
return resolve(article_id);
} catch (error) {
return reject(error);
}
});
});
}, (error) => reject(error));
});
}

attemptFetch = async (tries = 10, code) => {
if (tries === 0) {
this.props.api.notify.error(
"Adding article to the content list failed, please try again. If the problem persists, please contact support."
);

throw new Error('Failed to fetch article');
}

try {
const article = await this.props.publisher.getArticleByCode(code);
if (article) {
console.warn('Article added to the content list successfully.', article);
return article.id;
}
} catch (error) {
console.error('Error fetching article:', error);
}

await new Promise(resolve => setTimeout(resolve, 2000)); // Wait for 3 seconds

return this.attemptFetch(tries - 1, code);
};

handleSourceChange = (source) => {
if (source && (source.id === 'scheduled' || source.id === 'in_progress')) {
this._querySuperdeskArticles(source.id, true);
Expand Down Expand Up @@ -470,6 +497,10 @@ class Manual extends React.Component {
}

let list = { ...this.state.list };
let originalList = { ...this.state.list };
let originalArticles = { ...this.state.articles };
let originalChangesRecord = [...this.state.changesRecord];

if (source.droppableId === destination.droppableId) {
let items = reorder(
this.getList(source.droppableId),
Expand Down Expand Up @@ -516,14 +547,22 @@ class Manual extends React.Component {
return itemId === item_id;
});

change.content_id = res.id;
list.items[index].id = res.id;
change.content_id = res;
list.items[index].id = res;
}
return change;
});

list.loading = false;
this.setState({ list });
}).catch((err) => {
this.setState({
list: originalList,
articles: originalArticles,
changesRecord: originalChangesRecord
});

list.loading = false;
});
}
};
Expand Down
4 changes: 2 additions & 2 deletions client/services/PublisherFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ export function PublisherFactory(pubapi) {
* @returns {Promise}
* @description push article to publsiher
*/
publishSuperdeskArticle(article) {
return pubapi.publish("content/push", article);
publishSuperdeskArticle(status, article) {
return pubapi.publish(`content/push-with-options?status=${status}`, article);
}

/**
Expand Down

0 comments on commit 2f4dfc0

Please sign in to comment.