forked from usnationalarchives/sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbulktag.html
More file actions
121 lines (107 loc) · 4.91 KB
/
bulktag.html
File metadata and controls
121 lines (107 loc) · 4.91 KB
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
<html>
<title>Automated Tag Assistant</title>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
// Allow users to use 'enter' key on search box.
$('#user').keypress(function(enter){
if(enter.keyCode==13)
$('#login').click();
});
$('#pass').keypress(function(enter){
if(enter.keyCode==13)
$('#login').click();
});
$('#login').keypress(function(enter){
if(enter.keyCode==13)
$('#login').click();
});
function login(user, pass) {
var url = 'https://catalog.archives.gov/api/v1/login?user=' + user + '&password=' + pass
$.ajax({
type: 'POST',
url: url,
success: function(t) {
$("#loggedin").html('<h2>Hello, ' + t.opaResponse.user.fullName + '. How can I help?</h2>');
$("#bulktag").show();
token = t.opaResponse.credentials
},
error: function(f, textStatus, error){
$("#loggedin").html('<p>' + JSON.stringify(JSON.parse(JSON.parse(JSON.stringify(f)).responseText).opaResponse.error.description) + '</p>');
},
dataType: "json"
});
post = function(url) {
$("#robot").hide()
$.ajax({
type: 'POST',
url: url,
beforeSend: function(request) {
request.setRequestHeader("Authorization", token);
},
success: function(t) {
taggednaid = t.opaResponse.header.request.naId
$("#progress").append('<p> NAID <a href="https://catalog.archives.gov/id/' + taggednaid + '">' + taggednaid + '</a>: Added tag "' + tag + '"!</p>');
},
error: function(f, textStatus, error){
taggednaid = JSON.stringify(JSON.parse(JSON.parse(JSON.stringify(f)).responseText).opaResponse.error.naId)
description = JSON.stringify(JSON.parse(JSON.parse(JSON.stringify(f)).responseText).opaResponse.error.description)
error = JSON.stringify(JSON.parse(JSON.parse(JSON.stringify(f)).responseText).opaResponse.error['@code'])
$("#progress").append('<p> NAID <a href="https://catalog.archives.gov/id/' + taggednaid.replace('"','') + '">' + taggednaid + '</a>: ' + description + '</p>');
},
dataType: "json"
});
}
function bulktag(tag, naid, level) {
$("#bulktag").hide()
itemurl = 'https://catalog.archives.gov/api/v1?&exists=objects&type=description&description.item.parent' + level + '.naId=' + naid
$.getJSON(itemurl + '&rows=0', function(t) {
total = t.opaResponse.results.total
count = 0;
for (offset = 0; offset < total; offset++) {
var tagurl = itemurl + '&tag=' + tag + '&offset=' + offset
post(tagurl)
count++;
$("#loggedin").html('<h2>Beep boop. Tagged ' + count + ' descriptions with the tag "<a href="https://catalog.archives.gov/search?q=*:*&filter=(tagsExact:%22' + tag + '%22%20or%20objectTagsExact:%22' + tag + '%22)">' + tag + '</a>".</h2>');
}
});
if (level === 'Series') {
fileurl = 'https://catalog.archives.gov/api/v1?&exists=objects&type=description&description.fileUnit.parent' + level + '.naId=' + naid
$.getJSON(fileurl + '&rows=0', function(t) {
total = t.opaResponse.results.total
for (offset = 0; offset < total; offset++) {
var tagurl = fileurl + '&tag=' + tag + '&offset=' + offset
post(tagurl)
count++;
$("#loggedin").html('<h2>Beep boop. Tagged ' + count + ' descriptions with the tag "<a href="https://catalog.archives.gov/search?q=*:*&filter=(tagsExact:%22' + tag + '%22%20or%20objectTagsExact:%22' + tag + '%22)">' + tag + '</a>".</h2>');
}
});
}
}
$("#submit").click(function(event){
tag = $('#tag').val();
naid = $('#naid').val();
level = $('#level').val();
bulktag(tag, naid, level)
});
}
$("#login").click(function(event){
user = $('#user').val();
pass = $('#pass').val();
login(user, pass)
});
});
</script>
</head>
<body>
<h1 align="center">Automated Tag Assistant</h1>
<br/>
<center><span id="loggedin"><h2>Greetings, human! Please log in to begin.</h2><table>
<tr><td><p>Username: </td><td><input type="search" style="width:200px" id="user" placeholder="username" /></td>
<td>Password: </td><td><input type="password" style="width:200px" id="pass" placeholder="password" /></td>
<td><input style="width:75px" type="button" id="login" value="Log in" /></td></tr></table></span>
<span align="center" id="bulktag" style="display: none"><p>I would like to tag all descriptions with objects belonging to <select id="level"><option value="Series">series</option><option value="FileUnit">file unit</option></select> <input type="search" style="width:150px" id="naid" placeholder="NAID" /> with the tag <input type="search" style="width:150px" id="tag" placeholder="tag" />. <input style="width:75px" type="button" id="submit" value="Submit" /></p></span>
<br/><br/><a id="robot" href="https://catalog.archives.gov/id/6380554"><img src="https://catalog.archives.gov/OpaAPI/media/6380554/content/arcmedia/stillpix/330-cfd/1984/DN-SN-84-01256.jpeg" height="400"></a><span id="progress"></span></center>
</body>
</html>