-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
400 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
export default { | ||
complemgramExtended: { | ||
template: `<autoc | ||
input='input' | ||
isRawInput='isRawInput' | ||
on-change='onChange(output, isRawOutput)' | ||
type='lemgram' | ||
variant='affix' | ||
error-on-empty='true' | ||
error-message='choose_value'/> | ||
`, | ||
controller: [ | ||
"$scope", function($scope) { | ||
if($scope.model) { | ||
$scope.currentVal = $scope.model.replace(/[\\+\.\*:]*$/, "").replace(/^\\\+/, "") | ||
$scope.input = $scope.currentVal | ||
$scope.isRawInput = false | ||
} | ||
let setModel = () => { | ||
if(["starts_with_contains", "not_starts_with_contains"].includes($scope.orObj.op)) { | ||
$scope.model = $scope.currentVal + "\\+" | ||
} else if(["ends_with_contains", "not_ends_with_contains"].includes($scope.orObj.op)) { | ||
$scope.model = "\\+" + $scope.currentVal + ":.*" | ||
} else if(["incontains_contains", "not_incontains_contains"].includes($scope.orObj.op)) { | ||
$scope.model = "\\+" + $scope.currentVal + "\\+" | ||
} | ||
} | ||
$scope.$watch("orObj.op", () => { | ||
setModel() | ||
}) | ||
$scope.onChange = (output, isRawOutput) => { | ||
if(!isRawOutput) { | ||
$scope.currentVal = output | ||
setModel(output) | ||
} | ||
} | ||
}], | ||
}, | ||
msd: { | ||
template: ` | ||
<input ng-model="input" class="arg_value" escaper ng-model-options='{debounce : {default : 300, blur : 0}, updateOn: "default blur"}'> | ||
<span ng-click="onIconClick()" class="fa fa-info-circle"></span> | ||
`, | ||
controller: ["$scope", "$uibModal", function($scope, $uibModal) { | ||
let modal = null | ||
const msdHTML = settings.markup.msd | ||
const template = ` | ||
<div> | ||
<div class="modal-header"> | ||
<h3 class="modal-title">{{'msd_long' | loc:lang}}</h3> | ||
<span ng-click="clickX()" class="close-x">×</span> | ||
</div> | ||
<div class="modal-body msd-modal" ng-click="msdClick($event)">${msdHTML}</div> | ||
</div>` | ||
|
||
$scope.onIconClick = () => { | ||
modal = $uibModal.open({ | ||
template: template, | ||
scope: $scope | ||
}) | ||
} | ||
|
||
$scope.clickX = () => modal.close() | ||
|
||
$scope.msdClick = (event) => { | ||
const val = $(event.target).parent().data("value") | ||
if(!val) return | ||
$scope.input = val | ||
modal.close() | ||
} | ||
}] | ||
}, | ||
compwf: { | ||
template: "<input ng-model='currentVal'>", | ||
controller: ["$scope", function($scope) { | ||
let strip = str => str.replace(/[\\+\.\*]*$/, "").replace(/^\\\+/, "") | ||
if($scope.model && strip($scope.model) != ".+?") { | ||
$scope.currentVal = strip($scope.model) | ||
} | ||
let setModel = () => { | ||
let val = $scope.currentVal || ".+?" | ||
if(["starts_with_contains", "not_starts_with_contains"].includes($scope.orObj.op)) { | ||
$scope.model = val + "\\+" | ||
} else if(["ends_with_contains", "not_ends_with_contains"].includes($scope.orObj.op)) { | ||
$scope.model = "\\+" + val | ||
} else if(["incontains_contains", "not_incontains_contains"].includes($scope.orObj.op)) { | ||
$scope.model = "\\+" + val + "\\+" | ||
} | ||
} | ||
$scope.$watch("orObj.op", (newVal) => { | ||
setModel() | ||
}) | ||
$scope.$watch("currentVal", (newVal) => { | ||
setModel() | ||
}) | ||
}] | ||
}, | ||
dateInterval: { | ||
template: ` | ||
<div class="date_interval_arg_type"> | ||
<h3>{{'simple' | loc}}</h3> | ||
<form ng-submit="commitDateInput()"> | ||
<div class="" style="margin-bottom: 1rem;"> | ||
<span class="" style="display : inline-block; width: 32px; text-transform: capitalize;">{{'from' | loc}}</span> <input type="text" ng-blur="commitDateInput()" ng-model="fromDateString" placeholder="'1945' {{'or' | loc}} '1945-08-06'"/> | ||
</div> | ||
<div> | ||
<span class="" style="display : inline-block; width: 32px; text-transform: capitalize;">{{'to' | loc}}</span> <input type="text" ng-blur="commitDateInput()" ng-model="toDateString" placeholder="'1968' {{'or' | loc}} '1968-04-04'"/> | ||
</div> | ||
<button type="submit" class="hidden" /> | ||
</form> | ||
<div class="section mt-4"> | ||
<h3>{{'advanced' | loc}}</h3> | ||
<button class="btn btn-default btn-sm" popper no-close-on-click my="left top" at="right top"> | ||
<i class="fa fa-calendar"></i> <span style="text-transform: capitalize;">{{'from' | loc}} </span> | ||
</button> | ||
{{combined.format("YYYY-MM-DD HH:mm")}} | ||
<time-interval | ||
ng-click="from_click($event)" | ||
class="date_interval popper_menu dropdown-menu" | ||
date-model="from_date" | ||
time-model="from_time" | ||
model="combined" | ||
min-date="minDate" | ||
max-date="maxDate"></time-interval> | ||
</div> | ||
<div class="section"> | ||
<button class="btn btn-default btn-sm" popper no-close-on-click my="left top" at="right top"> | ||
<i class="fa fa-calendar"></i> <span style="text-transform: capitalize;">{{'to' | loc}} </span> | ||
</button> | ||
{{combined2.format("YYYY-MM-DD HH:mm")}} | ||
<time-interval | ||
ng-click="from_click($event)" | ||
class="date_interval popper_menu dropdown-menu" | ||
date-model="to_date" | ||
time-model="to_time" | ||
model="combined2" | ||
my="left top" | ||
at="right top" | ||
min-date="minDate" | ||
max-date="maxDate"></time-interval> | ||
</div> | ||
</div>`, | ||
controller: [ | ||
"$scope", "searches", "$timeout", function($scope, searches, $timeout) { | ||
let s = $scope | ||
let cl = settings.corpusListing | ||
|
||
let updateIntervals = function() { | ||
let moments = cl.getMomentInterval(); | ||
if (moments.length) { | ||
let [fromYear, toYear] = _.invokeMap(moments, "toDate") | ||
s.minDate = fromYear | ||
s.maxDate = toYear | ||
} else { | ||
let [from, to] = cl.getTimeInterval() | ||
s.minDate = moment(from.toString(), "YYYY").toDate(); | ||
s.maxDate = moment(to.toString(), "YYYY").toDate(); | ||
} | ||
}; | ||
s.commitDateInput = () => { | ||
if(s.fromDateString) { | ||
let simpleFrom = s.fromDateString.length == 4 | ||
s.from_date = moment(s.fromDateString, simpleFrom ? "YYYY" : "YYYY-MM-DD" ).toDate() | ||
} | ||
if(s.toDateString) { | ||
let simpleTo = s.toDateString.length == 4 | ||
if(simpleTo) { | ||
var dateString = `${s.toDateString}-12-31` | ||
} | ||
s.to_date = moment(dateString || s.dateString).toDate() | ||
s.to_time = moment("235959", "HHmmss").toDate() | ||
} | ||
} | ||
s.$on("corpuschooserchange", function() { | ||
updateIntervals() | ||
}) | ||
|
||
updateIntervals() | ||
|
||
s.from_click = function(event) { | ||
event.originalEvent.preventDefault() | ||
event.originalEvent.stopPropagation() | ||
} | ||
|
||
let getYear = function(val) { | ||
return moment(val.toString(), "YYYYMMDD").toDate(); | ||
} | ||
|
||
let getTime = function(val) { | ||
return moment(val.toString(), "HHmmss").toDate(); | ||
} | ||
|
||
if (!s.model) { | ||
s.from_date = s.minDate | ||
s.to_date = s.maxDate | ||
let [from, to] = _.invokeMap(cl.getMomentInterval(), "toDate") | ||
s.from_time = from | ||
s.to_time = to | ||
} else if (s.model.length === 4) { | ||
let [fromYear, toYear] = _.map(s.model.slice(0, 3), getYear) | ||
s.from_date = fromYear | ||
s.to_date = toYear | ||
let [fromTime, toTime] = _.map(s.model.slice(2), getTime) | ||
s.from_time = fromTime | ||
s.to_time = toTime | ||
} | ||
s.$watchGroup(["combined", "combined2"], function([combined, combined2]) { | ||
s.model = [ | ||
moment(s.from_date).format("YYYYMMDD"), | ||
moment(s.to_date).format("YYYYMMDD"), | ||
moment(s.from_time).format("HHmmss"), | ||
moment(s.to_time).format("HHmmss") | ||
] | ||
}) | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
export default { | ||
complemgram: { | ||
template: String.raw` | ||
<i ng-show="value == '|'" rel="localize[empty]" style="color : grey">[tom]</i> | ||
<ul ng-show="value != '|'"> | ||
<li ng-repeat="comp in values | limitTo:listLimit"> | ||
<span ng-repeat="value in comp.split('+') track by $index"> | ||
<span ng-if="!$first"> + </span> | ||
<a ng-click="onItemClick(value, $first, $last)" ng-bind-html="stringify(value) | trust"></a> | ||
</span> | ||
</li> | ||
<li class="link" ng-show="values.length > 1" ng-click="listLimit = listLimit < 10 ? 10 : 1"> | ||
{{listLimit < 10 ? 'complemgram_show_all': 'complemgram_show_one' | loc:lang}} ({{values.length - 1}}) | ||
</li> | ||
</ul> | ||
`, | ||
controller: ["$scope", "statemachine", function($scope, statemachine) { | ||
$scope.listLimit = 1 | ||
$scope.stringify = (lemgram) => util.lemgramToString(lemgram, true) | ||
$scope.values = $scope.value.split("|").filter(Boolean).map((item) => item.replace(/:.*$/, "")) | ||
$scope.onItemClick = (value, isPrefix, isSuffix) => { | ||
let isMiddle = !(isPrefix || isSuffix) | ||
|
||
let p = new URLSearchParams(location.hash.slice(1)) | ||
if(isPrefix) { | ||
p.set("prefix", "") | ||
p.delete("mid_comp") | ||
p.delete("suffix") | ||
} | ||
if(isMiddle) { | ||
p.set("mid_comp", "") | ||
p.delete("suffix") | ||
p.delete("prefix") | ||
} | ||
if(isSuffix) { | ||
p.set("suffix", "") | ||
p.delete("mid_comp") | ||
p.delete("prefix") | ||
} | ||
statemachine.send("SEARCH_LEMGRAM", {value}) | ||
console.log('## sending', value) | ||
p.set("search", "lemgram|" + value) | ||
|
||
window.location.hash = "#?" + p.toString().replace("=&", "&").replace(/=$/, "") | ||
|
||
} | ||
}] | ||
}, | ||
ivipVideo: (options) => ({ | ||
template: String.raw` | ||
<span class="link" ng-click="showVideoModal()">visa inspelning</span> | ||
<div id="video-modal" ng-controller="VideoCtrl"></div> | ||
`, | ||
controller: ["$scope", function($scope) { | ||
const startTime = $scope.sentenceData["sentence_start"] | ||
const endTime = $scope.sentenceData["sentence_end"] | ||
const path = $scope.sentenceData["text_mediafilepath"] | ||
const file = $scope.sentenceData["text_mediafile"] | ||
const ext = $scope.sentenceData["text_mediafileext"] | ||
|
||
$scope.showVideoModal = function () { | ||
const url = options.baseURL + path + file + "." + ext | ||
|
||
const modalScope = angular.element("#video-modal").scope() | ||
modalScope.videos = [{"url": url, "type": "video/mp4"}] | ||
modalScope.fileName = file + "." + ext | ||
modalScope.startTime = startTime / 1000 | ||
modalScope.endTime = endTime / 1000 | ||
|
||
// find start of sentence | ||
let startIdx = 0 | ||
for(let i = $scope.wordData.position; i >= 0; i--) { | ||
if(_.includes($scope.tokens[i]._open, "sentence")) { | ||
startIdx = i | ||
break | ||
} | ||
} | ||
|
||
// find end of sentence | ||
let endIdx = $scope.tokens.length - 1 | ||
for(let i = $scope.wordData.position; i < $scope.tokens.length; i++) { | ||
if(_.includes($scope.tokens[i]._close, "sentence")) { | ||
endIdx = i | ||
break | ||
} | ||
} | ||
|
||
modalScope.sentence = _.map($scope.tokens.slice(startIdx, endIdx + 1), "word").join(" ") | ||
modalScope.open() | ||
} | ||
}] | ||
}), | ||
lsiImage: { | ||
template: String.raw` | ||
<div> | ||
<a target="_blank" ng-href="{{pageUrl}}" ng-show="pageUrl"> | ||
<img ng-src="https://spraakbanken.gu.se/korp/data/lsi/faksimil_thumb/thumb.lsi-v{{volumeName}}-{{pageNumber2}}.jpg"> | ||
</a> | ||
</div> | ||
`, | ||
controller: ["$scope", function($scope) { | ||
$scope.pageUrl = $scope.sentenceData["page_page_url"] | ||
const re = new RegExp("volume=(.*-.*)&pages=.*#page/(.*)/mode") | ||
const matches = $scope.pageUrl.match(re) | ||
$scope.volumeName = matches[1] | ||
const pageNumber = matches[2] | ||
$scope.pageNumber2 = ("00"+pageNumber).slice(-3) | ||
}] | ||
} | ||
} |
Oops, something went wrong.