Skip to content

Commit 1df2254

Browse files
committed
use textarea for edit entity
1 parent 213330b commit 1df2254

6 files changed

Lines changed: 120 additions & 4 deletions

File tree

OpenFlow/src/public/CommonControllers.ts

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,75 @@ module openflow {
392392
}
393393
}
394394

395+
396+
export class textarea implements ng.IDirective {
397+
// restrict = 'E';
398+
// require = 'ngModel';
399+
replace = true;
400+
constructor(public $location: ng.ILocationService, public $timeout: ng.ITimeoutService) {
401+
402+
}
403+
404+
link: ng.IDirectiveLinkFn = (scope: ng.IScope, element: ng.IAugmentedJQuery, attr: ng.IAttributes, ngModelCtrl: any) => {
405+
if (!element.hasClass("autogrow")) {
406+
console.log("no autogrow for you today");
407+
// no autogrow for you today
408+
return;
409+
}
410+
411+
// get possible minimum height style
412+
var minHeight = parseInt(window.getComputedStyle(element[0]).getPropertyValue("min-height")) || 0;
413+
414+
// prevent newlines in textbox
415+
// element.on("keydown", function (evt) {
416+
// if (evt.which === 13) {
417+
// evt.preventDefault();
418+
// }
419+
// });
420+
421+
element.on("input", function (evt) {
422+
var contentHeight2 = (this as any).scrollHeight;
423+
var firstrun = element.attr("firstrun");
424+
if (contentHeight2 > 1000) {
425+
if (firstrun === null || firstrun === undefined) {
426+
element.attr("firstrun", "false");
427+
} else {
428+
return;
429+
}
430+
}
431+
element.css({
432+
paddingTop: 0,
433+
height: 0,
434+
minHeight: 0
435+
});
436+
437+
var contentHeight = (this as any).scrollHeight;
438+
var borderHeight = (this as any).offsetHeight;
439+
440+
element.css({
441+
paddingTop: ~~Math.max(0, minHeight - contentHeight) / 2 + "px",
442+
minHeight: null, // remove property
443+
height: contentHeight + borderHeight + "px" // because we're using border-box
444+
});
445+
});
446+
447+
// watch model changes from the outside to adjust height
448+
scope.$watch(attr.ngModel, trigger);
449+
450+
// set initial size
451+
trigger();
452+
453+
function trigger() {
454+
setTimeout(element.triggerHandler.bind(element, "input"), 1);
455+
}
456+
}
457+
static factory(): ng.IDirectiveFactory {
458+
const directive = ($location: ng.ILocationService, $timeout: ng.ITimeoutService) => new textarea($location, $timeout);
459+
directive.$inject = ['$location', '$timeout'];
460+
return directive;
461+
}
462+
}
463+
395464
async function getString(locale: any, lib: string, key: string): Promise<any> {
396465
return new Promise((resolve) => {
397466
try {
@@ -617,7 +686,7 @@ module openflow {
617686
public id: string = null;
618687
public keys: string[] = [];
619688
public autorefresh: boolean = false;
620-
public autorefreshinterval: number = 2000;
689+
public autorefreshinterval: number = 30 * 1000;
621690
public autorefreshpromise: any = null;
622691
public preloadData: any = null;
623692
public postloadData: any = null;

OpenFlow/src/public/Controllers.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,7 @@ module openflow {
14821482
super($scope, $location, $routeParams, $interval, WebSocketClient, api);
14831483
console.debug("EntityCtrl");
14841484
this.collection = $routeParams.collection;
1485+
this.postloadData = this.processdata;
14851486
WebSocketClient.onSignedin(async (user: TokenUser) => {
14861487
this.usergroups = await this.api.Query("users", {});
14871488
if (this.id !== null && this.id !== undefined) {
@@ -1498,6 +1499,29 @@ module openflow {
14981499
}
14991500
});
15001501
}
1502+
processdata() {
1503+
// $(document)
1504+
// .one('focus.autoExpand', 'textarea.autoExpand', function () {
1505+
// var savedValue = this.value;
1506+
// this.value = '';
1507+
// this.baseScrollHeight = this.scrollHeight;
1508+
// this.value = savedValue;
1509+
1510+
// var minRows = this.getAttribute('data-min-rows') | 0, rows;
1511+
// this.rows = minRows;
1512+
// rows = Math.ceil((this.scrollHeight - this.baseScrollHeight) / 16);
1513+
// this.rows = minRows + rows;
1514+
// })
1515+
// .on('input.autoExpand', 'textarea.autoExpand', function () {
1516+
// var minRows = this.getAttribute('data-min-rows') | 0, rows;
1517+
// // this.rows = minRows;
1518+
// rows = Math.ceil((this.scrollHeight - this.baseScrollHeight) / 16);
1519+
// if (this.rows < (minRows + rows)) {
1520+
// this.rows = minRows + rows;
1521+
// }
1522+
// });
1523+
if (!this.$scope.$$phase) { this.$scope.$apply(); }
1524+
}
15011525
togglejson() {
15021526
this.showjson = !this.showjson;
15031527
if (this.showjson) {

OpenFlow/src/public/Entity.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ <h1 class="pagetitle"><span translate lib="web">detailsfor</span> {{ctrl.model.n
4949
<label class="col-sm-3 control-label"><span translate lib="web">{{ key }}</span>: <a href=""
5050
ng-click="ctrl.removekey(key)" translate lib="web">delete</a></label>
5151
<div class="col-sm-9">
52+
<textarea class='autogrow form-control' rows='3' data-min-rows='3'
53+
ng-model="ctrl.model[key]"></textarea>
54+
<!--
5255
<input ng-model="ctrl.model[key]" class="form-control input-md" ng-disabled="ctrl.loading==true" />
56+
-->
5357
</div>
5458
</div>
5559
</section>
@@ -68,7 +72,9 @@ <h1 class="pagetitle"><span translate lib="web">detailsfor</span> {{ctrl.model.n
6872
<div class="form-group">
6973
<label class="col-sm-3 control-label" translate lib="web">json</label>
7074
<div class="col-sm-9">
71-
<textarea class="form-control" rows="5" ng-model="ctrl.jsonmodel" style="max-width: 100%;"></textarea>
75+
<!-- <textarea class="form-control" rows="5" ng-model="ctrl.jsonmodel" style="max-width: 100%;"></textarea> -->
76+
77+
<textarea class='autogrow form-control' rows='3' data-min-rows='3' ng-model="ctrl.jsonmodel"></textarea>
7278

7379
<!-- <textarea msd-elastic class="form-control" ></textarea> -->
7480
</div>

OpenFlow/src/public/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module openflow {
88
.controller("Providers", ProvidersCtrl)
99
.directive("timesince", timesince.factory())
1010
.directive("translate", translate.factory())
11+
.directive("textarea", textarea.factory())
1112
.service("WebSocketClient", WebSocketClient)
1213
.service("api", api);
1314
// .directive("todoBlur", todoBlur)

OpenFlow/src/public/site.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,20 @@
209209
}
210210
body {
211211
background: transparent none !important;
212-
}
212+
}
213+
214+
215+
/*
216+
textarea{
217+
display: block;
218+
box-sizing: padding-box;
219+
overflow: hidden;
220+
221+
padding: 10px;
222+
width: 250px;
223+
font-size: 14px;
224+
margin: 50px auto;
225+
border-radius: 6px;
226+
box-shadow: 2px 2px 8px rgba(black, .3);
227+
border: 0;
228+
} */

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.319
1+
0.0.320

0 commit comments

Comments
 (0)