2022-07-27 16:22:45 +03:00
|
|
|
import Controller from '@ember/controller';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
export default class ExploreController extends Controller {
|
2022-10-07 16:32:54 +03:00
|
|
|
@service explore;
|
|
|
|
@service router;
|
2022-07-27 16:22:45 +03:00
|
|
|
|
|
|
|
get exploreCredentials() {
|
|
|
|
const explore = this.model.findBy('slug', 'ghost-explore');
|
|
|
|
const adminKey = explore.adminKey;
|
|
|
|
|
2022-08-03 13:21:46 +03:00
|
|
|
return adminKey.secret;
|
2022-07-27 16:22:45 +03:00
|
|
|
}
|
|
|
|
|
2022-10-07 16:32:54 +03:00
|
|
|
get visibilityClass() {
|
|
|
|
return this.explore.isIframeTransition ? 'explore iframe-explore-container' : ' explore fullscreen-explore-container';
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
closeConnect() {
|
|
|
|
if (this.explore.isIframeTransition) {
|
|
|
|
this.router.transitionTo('/explore');
|
|
|
|
} else {
|
|
|
|
this.router.transitionTo('/dashboard');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-27 16:22:45 +03:00
|
|
|
@action
|
|
|
|
submitExploreSite() {
|
|
|
|
const token = this.exploreCredentials;
|
2022-10-07 16:32:54 +03:00
|
|
|
const apiUrl = this.explore.apiUrl;
|
2022-07-27 16:22:45 +03:00
|
|
|
|
|
|
|
const query = new URLSearchParams();
|
|
|
|
|
|
|
|
query.append('token', token);
|
|
|
|
query.append('url', apiUrl);
|
|
|
|
|
2022-10-07 16:32:54 +03:00
|
|
|
if (this.explore.isIframeTransition) {
|
|
|
|
this.explore.sendRouteUpdate({path: this.explore.submitRoute, queryParams: query.toString()});
|
|
|
|
|
|
|
|
// Set a short timeout to give Explore enough time to navigate
|
|
|
|
// to the submit page and fetch the required site data
|
|
|
|
setTimeout(() => {
|
|
|
|
this.explore.toggleExploreWindow(true);
|
|
|
|
this.router.transitionTo('explore');
|
|
|
|
}, 500);
|
|
|
|
} else {
|
|
|
|
// Ghost Explore URL to submit a new site
|
|
|
|
const destination = new URL(`${this.explore.exploreUrl}${this.explore.submitRoute}`);
|
|
|
|
destination.search = query;
|
|
|
|
|
|
|
|
window.location = destination.toString();
|
|
|
|
}
|
2022-07-27 16:22:45 +03:00
|
|
|
}
|
|
|
|
}
|