Skip to content

Commit

Permalink
WIp
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremythuff committed Jan 2, 2019
1 parent 7533c21 commit 4b0215f
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 59 deletions.
53 changes: 33 additions & 20 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,42 @@
<tamuheader title="Sage"></tamuheader>

<alerts types="WARNING,ERROR"></alerts>

<div class="container-fluid">
<div class="container">
<div class="col-md-12" ng-controller="ManagementController">
<div class="row">
<br>
<nav class="pull-right">
<div class="dropdown">
<span class="glyphicon glyphicon-user"></span>

<a class="dropdown-toggle clickable" data-toggle="dropdown" aria-expanded="false">
<username></username> <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li><a href="users">Manage Users</a></li>
<li ng-if="isAdmin() || isAssuming() == 'true'" role="presentation" class="divider"></li>
<li ng-if="isAdmin() || isAssuming() == 'true'" role="presentation" class="dropdown-header">Admin Actions header</li>
<li ng-if="isAdmin() || isAssuming() == 'true'">
<a href ng-if="isAssuming() == 'false'" data-toggle="modal" ng-click="openModal('#assumeUserModal')">{{assumedControl.button}}</a>
<a href ng-if="isAssuming() == 'true'" ng-click="assumeUser(assume)">{{assumedControl.button}}</a>
</li>
</ul>
</div>
</nav>
<br>
</div>
</div>
</div>
</div>
</div>

<single-result-viewer></single-result-viewer>

<div class="container-fluid">
<div class="container">
<div class="col-md-12" ng-controller="ManagementController">
<div class="row">
<nav class="pull-right">
<div class="dropdown">
<span class="glyphicon glyphicon-user"></span>

<a class="dropdown-toggle clickable" data-toggle="dropdown" aria-expanded="false">
<username></username> <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li><a href="users">Manage Users</a></li>
<li ng-if="isAdmin() || isAssuming() == 'true'" role="presentation" class="divider"></li>
<li ng-if="isAdmin() || isAssuming() == 'true'" role="presentation" class="dropdown-header">Admin Actions header</li>
<li ng-if="isAdmin() || isAssuming() == 'true'">
<a href ng-if="isAssuming() == 'false'" data-toggle="modal" ng-click="openModal('#assumeUserModal')">{{assumedControl.button}}</a>
<a href ng-if="isAssuming() == 'true'" ng-click="assumeUser(assume)">{{assumedControl.button}}</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="row">
<div ng-view class="view"></div>
</div>
Expand Down Expand Up @@ -201,6 +213,7 @@

<!-- Components -->
<script src="components/multiSuggestionInputComponent.js"></script>
<script src="components/singleResultViewerComponent.js"></script>

<!-- Directives -->
<script src="directives/contentEditableDirective.js"></script>
Expand Down
92 changes: 92 additions & 0 deletions src/main/webapp/app/components/singleResultViewerComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
sage.component("singleResultViewer", {
templateUrl: "views/components/singleResultViewer.html",
bindings: {},
controller: function($scope, $routeParams, SingleResultContextService, $q) {

$scope.ready = false;

var getContentType = function(url) {

var defer = $q.defer();

var extension;

if(url) {
extension = url.split('.').pop();
}

if(extension) {
var ct = "default";
var keys = Object.keys(appConfig.contentMap);
for(var i in keys) {
var key = keys[i]
var types = appConfig.contentMap[key];
var index = types.indexOf(extension);
if(index !== -1) {
defer.resolve(types[index] || ct);
break;
}
}
} else {
var xhttp = new XMLHttpRequest();
xhttp.open('HEAD', url);
xhttp.onreadystatechange = function () {
if (this.readyState == this.DONE) {
var ct = this.getResponseHeader("Content-Type");
defer.resolve(ct);
}
};
xhttp.send();
}

return defer.promise;
};

$scope.singleResultMode = function() {
return $routeParams.resultId != null;
};

SingleResultContextService.getSingleResult().then(function(sr) {

$scope.singleResultContext = sr;

getContentType().then(function(ct) {
console.log(ct);
$scope.contentType = ct;
$scope.ready = true;
});

console.log($scope.singleResultContext);

});

}
});

sage.service("SingleResultContextService", function($q) {

var singleResultContextService = this;

var defer;

var singleResult;

singleResultContextService.getSingleResult = function() {

defer = $q.defer();

if(singleResult) {
defer.resolve(singleResult);
}

return defer.promise;
};

singleResultContextService.setSingleResult = function(sr, trigger) {
trigger = false;
singleResult = sr;
if(defer) defer.resolve(singleResult);
trigger = true;
};

});
6 changes: 3 additions & 3 deletions src/main/webapp/app/config/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ var appConfig = {

// Set this to 'admin' or 'user' if using mock AuthService
// otherwise set to null or false
'mockRole': null,

'contentMap': {"image": ["image/jpeg","image/png","image/gif"],"seadragon": ["image/jp2","image/tiff"]},

'cantaloupeBaseUrl': 'https://api-dev.library.tamu.edu/iiif/2/',
'contentMap': {"image": ["image/jpeg","image/png","image/gif", "text/html;charset=UTF-8", "jpg"],"seadragon": ["image/jp2","image/tiff"]},

'mockRole': null,
'cantaloupeBaseUrl': 'https://api-dev.library.tamu.edu/iiif/2/',

'defaultThumbnailURI': "resources/images/default-thumbnail.jpg"

Expand Down
29 changes: 1 addition & 28 deletions src/main/webapp/app/controllers/singleResultController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sage.controller('SingleResultController', function ($controller, $scope, $routeParams, SingleResultContext, appConfig) {
sage.controller('SingleResultController', function ($controller, $scope, $routeParams, SingleResultContext) {

angular.extend(this, $controller('CoreAdminController', {
$scope: $scope
Expand All @@ -8,33 +8,6 @@ sage.controller('SingleResultController', function ($controller, $scope, $routeP
slug: $routeParams.slug,
resultId: $routeParams.resultId,
});

$scope.getContentType = function(url) {
var contentType, extension;

if(url) {
extension = url.split('.').pop();
console.log(extension);
}

if(extension) {
contentType = extension;
} else {
var xhttp = new XMLHttpRequest();
xhttp.open('HEAD', url);
xhttp.onreadystatechange = function () {
if (this.readyState == this.DONE) {
console.log(this.status);
var t = this.getResponseHeader("Content-Type");
console.log(t);
contentType = t;
}
};
xhttp.send();
}

return contentType;
};

$scope.singleResultContext = singleResultContext;

Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/app/directives/contentViewerDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ sage.directive("contentviewer", function($filter) {
typeLoop:
for (var type in viewerMap) {
for (var supportedType in viewerMap[type]) {
console.log($scope.contentType);
if ($scope.contentType === viewerMap[type][supportedType]) {
viewerTemplate = type;
console.log(viewerTemplate);
break typeLoop;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/app/model/singleResultContextModel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sage.model("SingleResultContext", function ($q, $location, $routeParams, WsApi, Result, Field, Search) {
sage.model("SingleResultContext", function ($q, $location, $routeParams, WsApi, SingleResultContextService) {
return function SingleResultContext() {

var singleResultContext = this;
Expand All @@ -12,6 +12,7 @@ sage.model("SingleResultContext", function ($q, $location, $routeParams, WsApi,
}).then(function(res) {
var rc = angular.fromJson(res.body).payload.SingleResultContext;
angular.extend(singleResultContext, rc);
SingleResultContextService.setSingleResult(singleResultContext);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,8 @@
}
}

}

.single-item-viewer {
font: initial;
}
5 changes: 5 additions & 0 deletions src/main/webapp/app/views/components/singleResultViewer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="jumbotron single-result-viewer" ng-if="singleResultMode()">
<div class="container">
<contentviewer ng-if="ready" content-type="contentType" resource="singleResultContext.resourceLocationUri | removeBrackets"></contentviewer>
</div>
</div>
7 changes: 0 additions & 7 deletions src/main/webapp/app/views/discovery/single-result.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<h1>{{singleResultContext.title | removeBrackets}}</h1>

<div class="jumbotron">
<div class="container">
<contentviewer content-type="getContentType(singleResultContext.resourceLocationUri| removeBrackets)" resource="singleResultContext.resourceLocationUri | removeBrackets"></contentviewer>
<!-- <img class="media-object" default-src="defaultThumbnailURI" ng-src="{{singleResultContext.resourceLocationUri | removeBrackets}}" alt="picture of: {{result.title}}"> -->
</div>
</div>

<div class="row">
<div class="col-xs-9 col-xs-offset-1">
<dl class="dl-horizontal dc-result-metadata">
Expand Down

0 comments on commit 4b0215f

Please sign in to comment.