-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
162 lines (142 loc) · 5.51 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<html>
<head>
<script src="https://unpkg.com/@woodwing/assets-client-sdk"></script>
<script language="JavaScript">
var contextService;
var context;
/**
* Set the info message
*/
function setMessage (message) {
document.getElementById("message").innerHTML = message;
}
/**
* Returns the URL of the studio server as configured in the plugin properties
*/
function getStudioServerURL () {
return context.plugin.configProperties.studioServerURL.value + "?protocol=JSON&method=QueryObjects&ww-app=Content+Station";
}
/**
* Returns the URL of the studio client as configured in the plugin properties
*/
function getStudioClientURL () {
var studioClientURL = context.plugin.configProperties.studioClientURL.value;
if (studioClientURL.charAt(studioClientURL.length-1) != "/") {
studioClientURL += "/";
}
studioClientURL += "#/ids/IDs=";
return studioClientURL;
}
/**
* Start searching and open the Studio Client
*/
async function onLoad() {
(async () => {
contextService = await window.AssetsClientSdk.AssetsPluginContext.get();
context = contextService.context;
//Search in Assets for all the variants of the selected images
var query = "";
context.activeTab.assetSelection.forEach(function (asset) {
if (query != "") {
query += " OR ";
}
query += "id:" + asset.id + " OR masterId:" + asset.id;
});
var searchResults = await contextService.fetch('/services/search', {
method: 'POST',
body: {
q: query,
sort: 'filename'
}
});
var studioQuery = {
"method":"QueryObjects",
"params":[
{
"Params":[
],
"RequestProps": ["ID","Name","Type"],
"MaxEntries":0,
"Ticket":null
}]
,"id":0,
"jsonrpc":"2.0"
};
var studioIds = [];
searchResults.hits.forEach(function (asset) {
if (asset.metadata.sceId) {
studioQuery.params[0].Params.push (
{
"Property":"ChildId",
"Operation":"=",
"Value":asset.metadata.sceId,
"__classname__":"QueryParam"
}
);
studioIds.push (asset.metadata.sceId);
}
});
//Search in Studio for all the related files
if (studioQuery.params[0].Params.length > 0) {
fetch(getStudioServerURL(), {
mode: 'cors',
credentials: 'include', // include cookie with Studio server ticket!
method: 'POST',
headers: {'X-WoodWing-Application': 'Content Station'},
body: JSON.stringify(studioQuery)
}).then(function(response) {
return response.json();
}).then(function(data) {
if (data.error) {
if (data.error.data.detail == "SCEntError_InvalidTicket") {
setMessage ("Please login to <a href='" + getStudioClientURL () + "' target='_blank'>Studio</a> first");
} else {
setMessage (data.error.message);
}
} else if (data.result.TotalEntries > 0) {
data.result.Rows.forEach(function (row) {
studioIds.push (row[0]);
});
//Open the studio client
window.open(getStudioClientURL () + studioIds.join("."));
contextService.close();
} else {
setMessage ("No related files could be found");
}
});
} else {
setMessage ("No related files could be found");
}
})();
}
window.onload = onLoad;
</script>
<style type="text/css">
@import url('https://fonts.googleapis.com/css?family=Lato:300,400,700');
* {
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
font-size: 14px;
font-weight: 400;
}
html,
body {
font-family: Lato, sans-serif;
width: 100%;
height: 100%;
margin: 0px;
color: #777;
}
.infoPanel {
margin-top: 35px;
margin-left: 20px;
font-size: 12px
}
</style>
</head>
<body>
<div class="infoPanel" >
<p id="message">Searching for related files, one moment....</p>
</div>
</body>
</html>