@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
189 lines (187 loc) • 7.07 kB
JavaScript
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { get } from '../utils/ajax';
import { toQueryString } from '../utils/object';
import { map, pluck } from 'rxjs/operators';
import { createPagedArray } from '../utils/array';
import { prepareVirtualItemProps } from '../utils/content';
export function fetchLegacyGetGoLiveItems(site, sortBy, sortAsc, includeInProgress, filterByNumber) {
const qs = toQueryString(
Object.assign(
Object.assign(
Object.assign(
{ site },
sortBy
? {
sort: sortBy,
ascending: sortAsc
}
: {}
),
includeInProgress && { includeInProgress }
),
filterByNumber && { num: filterByNumber }
)
);
return get(`/studio/api/1/services/api/1/workflow/get-go-live-items.json${qs}`).pipe(pluck('response'));
}
export function fetchLegacyUserActivities(site, user, sortBy, sortAsc, numResults, filterBy, excludeLive) {
const qs = toQueryString(
Object.assign(
Object.assign(
Object.assign(
Object.assign(
{ site, user },
sortBy
? {
sort: sortBy,
ascending: sortAsc
}
: {}
),
numResults && { num: numResults }
),
filterBy && { filterType: filterBy }
),
{ excludeLive }
)
);
return get(`/studio/api/1/services/api/1/activity/get-user-activities.json${qs}`).pipe(pluck('response'));
}
export function fetchLegacyScheduledItems(site, sort, ascending, filterType) {
const qs = toQueryString({
site,
sort,
ascending,
filterType
});
return get(`/studio/api/1/services/api/1/deployment/get-scheduled-items.json${qs}`).pipe(pluck('response'));
}
export function fetchLegacyDeploymentHistory(siteId, days, numResults, filterBy) {
const qs = toQueryString(
Object.assign(
Object.assign(Object.assign({ siteId }, days && { days }), numResults && { num: numResults }),
filterBy && { filterType: filterBy }
)
);
return get(`/studio/api/2/publish/history.json${qs}`).pipe(pluck('response'));
}
export function fetchActivity(siteId, options) {
const qs = toQueryString(Object.assign({ siteId }, options), { arrayFormat: 'comma' });
return get(`/studio/api/2/dashboard/activity${qs}`).pipe(
map(({ response: { activities, total, offset, limit } }) =>
Object.assign(activities, {
total,
offset,
limit
})
)
);
}
export function fetchMyActivity(siteId, options) {
const qs = toQueryString(Object.assign({ siteId }, options));
return get(`/studio/api/2/dashboard/activity/me${qs}`).pipe(
map(({ response: { activities, total, offset, limit } }) =>
Object.assign(activities, {
total,
offset,
limit
})
)
);
}
export function fetchPendingApproval(siteId, options) {
const qs = toQueryString(Object.assign({ siteId }, options));
return get(`/studio/api/2/dashboard/content/pending_approval${qs}`).pipe(
map(({ response }) =>
createPagedArray(
response.publishingItems.map((item) => prepareVirtualItemProps(item)),
response
)
)
);
}
export function fetchPendingApprovalPackageItems(siteId, packageId) {
const qs = toQueryString({ siteId });
return get(`/studio/api/2/dashboard/content/pending_approval/${packageId}${qs}`).pipe(
pluck('response', 'publishingPackageItems'),
map((items) => items.map((item) => prepareVirtualItemProps(item)))
);
}
export function fetchUnpublished(siteId, options) {
const qs = toQueryString(Object.assign({ siteId }, options));
return get(`/studio/api/2/dashboard/content/unpublished${qs}`).pipe(
map(({ response }) =>
createPagedArray(
response.unpublishedItems.map((item) => prepareVirtualItemProps(item)),
response
)
)
);
}
export function fetchScheduled(siteId, options) {
const qs = toQueryString(Object.assign({ siteId }, options));
return get(`/studio/api/2/dashboard/publishing/scheduled${qs}`).pipe(
map(({ response }) => createPagedArray(response.publishingPackages, response))
);
}
export function fetchScheduledPackageItems(siteId, packageId) {
const qs = toQueryString({ siteId });
return get(`/studio/api/2/dashboard/publishing/scheduled/${packageId}${qs}`).pipe(
pluck('response', 'publishingPackageItems'),
map((items) => items.map((item) => prepareVirtualItemProps(item)))
);
}
export function fetchPublishingHistory(siteId, options) {
const qs = toQueryString(Object.assign({ siteId }, options));
return get(`/studio/api/2/dashboard/publishing/history${qs}`).pipe(
map(({ response }) => createPagedArray(response.publishingPackages, response))
);
}
export function fetchPublishingHistoryPackageItems(siteId, packageId) {
const qs = toQueryString({ siteId });
return get(`/studio/api/2/dashboard/publishing/history/${packageId}${qs}`).pipe(
pluck('response', 'publishingPackageItems'),
map((items) => items.map((item) => prepareVirtualItemProps(item)))
);
}
export function fetchExpired(siteId, options) {
const qs = toQueryString(Object.assign({ siteId }, options));
return get(`/studio/api/2/dashboard/content/expired${qs}`).pipe(pluck('response', 'items'));
}
export function fetchExpiring(siteId, options) {
const qs = toQueryString(Object.assign({ siteId }, options));
return get(`/studio/api/2/dashboard/content/expiring${qs}`).pipe(pluck('response', 'items'));
}
export function fetchPublishingStats(siteId, days) {
const qs = toQueryString({ siteId, days });
return get(`/studio/api/2/dashboard/publishing/stats${qs}`).pipe(pluck('response', 'publishingStats'));
}