Skip to content

Commit 633513d

Browse files
committed
Display a DN entry with language tags - work for #16
1 parent 705bfb2 commit 633513d

File tree

12 files changed

+132
-50
lines changed

12 files changed

+132
-50
lines changed

app/Classes/LDAP/Attribute.php

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,7 @@ public function __toString(): string
178178
return $this->name;
179179
}
180180

181-
public function addValue(string $tag,string $value): void
182-
{
183-
$this->_values->put(
184-
$tag,
185-
$this->_values
186-
->get($tag,collect())
187-
->push($value));
188-
}
181+
/* INTERFACE */
189182

190183
public function current(): mixed
191184
{
@@ -237,6 +230,24 @@ public function offsetUnset(mixed $offset): void
237230
// We cannot clear values using array syntax
238231
}
239232

233+
/* METHODS */
234+
235+
public function addValue(string $tag,array $values): void
236+
{
237+
$this->_values->put(
238+
$tag,
239+
array_unique(array_merge($this->_values
240+
->get($tag,[]),$values)));
241+
}
242+
243+
public function addValueOld(string $tag,array $values): void
244+
{
245+
$this->_values_old->put(
246+
$tag,
247+
array_unique(array_merge($this->_values_old
248+
->get($tag,[]),$values)));
249+
}
250+
240251
/**
241252
* Return the hints about this attribute, ie: RDN, Required, etc
242253
*
@@ -266,8 +277,10 @@ public function hints(): array
266277
*/
267278
public function isDirty(): bool
268279
{
269-
return ($this->values_old->count() !== $this->values->count())
270-
|| ($this->values->diff($this->values_old)->count() !== 0);
280+
return (($a=$this->values_old->dot())->keys()->count() !== ($b=$this->values->dot())->keys()->count())
281+
|| ($a->values()->count() !== $b->values()->count())
282+
|| ($a->keys()->diff($b->keys())->count() !== 0)
283+
|| ($a->values()->diff($b->values())->count() !== 0);
271284
}
272285

273286
/**
@@ -329,4 +342,18 @@ public function required(): Collection
329342
? $this->oc->intersect($this->required_by->keys())->sort()
330343
: collect();
331344
}
345+
346+
public function tagValues(string $tag=''): Collection
347+
{
348+
return $this->_values
349+
->filter(fn($item,$key)=>($key === $tag))
350+
->values();
351+
}
352+
353+
public function tagValuesOld(string $tag=''): Collection
354+
{
355+
return $this->_values_old
356+
->filter(fn($item,$key)=>($key === $tag))
357+
->values();
358+
}
332359
}

app/Ldap/Entry.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ public function getLangTags(): Collection
309309
->map(fn($item)=>$item
310310
->values
311311
->keys()
312-
->filter(fn($item)=>preg_match(sprintf('/%s+;?/',self::TAG_CHARS_LANG),$item)))
312+
->filter(fn($item)=>preg_match(sprintf('/%s+;?/',self::TAG_CHARS_LANG),$item))
313+
->map(fn($item)=>preg_replace('/lang-/','',$item))
314+
)
313315
->filter(fn($item)=>$item->count());
314316
}
315317

app/View/Components/Attribute.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ class Attribute extends Component
1212
public bool $edit;
1313
public bool $new;
1414
public bool $old;
15-
public ?string $na;
15+
public string $langtag;
16+
public ?string $na; // Text to render if the LDAPAttribute is null
1617

1718
/**
1819
* Create a new component instance.
1920
*/
20-
public function __construct(?LDAPAttribute $o,bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE,?string $na=NULL)
21+
public function __construct(?LDAPAttribute $o,bool $edit=FALSE,bool $old=FALSE,bool $new=FALSE,string $langtag='',?string $na=NULL)
2122
{
2223
$this->o = $o;
2324
$this->edit = $edit;
2425
$this->old = $old;
2526
$this->new = $new;
27+
$this->langtag = $langtag;
2628
$this->na = $na;
2729
}
2830

app/View/Components/AttributeType.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ class AttributeType extends Component
1313
{
1414
private LDAPAttribute $o;
1515
private bool $new;
16+
private string $langtag;
1617

1718
/**
1819
* Create a new component instance.
1920
*/
20-
public function __construct(LDAPAttribute $o,bool $new=FALSE)
21+
public function __construct(LDAPAttribute $o,bool $new=FALSE,string $langtag='')
2122
{
2223
$this->o = $o;
2324
$this->new = $new;
25+
$this->langtag = $langtag;
2426
}
2527

2628
/**
@@ -30,6 +32,7 @@ public function render(): View|Closure|string
3032
{
3133
return view('components.attribute-type')
3234
->with('o',$this->o)
33-
->with('new',$this->new);
35+
->with('new',$this->new)
36+
->with('langtag',$this->langtag);
3437
}
3538
}

public/css/custom.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ input.form-control.input-group-end {
3030

3131
.custom-tooltip-danger {
3232
--bs-tooltip-bg: var(--bs-danger);
33+
}
3334

35+
.custom-tooltip {
36+
--bs-tooltip-bg: var(--bs-gray-900);
3437
}
3538

3639
.tooltip {

resources/views/components/attribute-type.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</div>
1616
</div>
1717

18-
<x-attribute :o="$o" :edit="true" :new="$new ?? FALSE"/>
18+
<x-attribute :o="$o" :edit="true" :new="$new ?? FALSE" :langtag="$langtag"/>
1919
</div>
2020
</div>
2121

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
<!-- $o=Attribute::class -->
22
<x-attribute.layout :edit="$edit ?? FALSE" :new="$new ?? FALSE" :o="$o">
3-
@foreach(old($o->name_lc,($new ?? FALSE) ? [NULL] : $o->values) as $tag=>$tagvalues)
4-
<div class="row p-2 border rounded">
5-
<div class="col-2">
6-
{{ $tag }}
7-
</div>
8-
<div class="col-10">
9-
<div class="row">
10-
<div class="col-12">
11-
@foreach($tagvalues as $value)
12-
@if(($edit ?? FALSE) && ! $o->is_rdn)
13-
<div class="input-group has-validation">
14-
<input type="text" @class(['form-control','is-invalid'=>($e=$errors->get($o->name_lc.'.'.$loop->index)),'mb-1','border-focus'=>($o->values->contains($value))]) name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ ! is_null($x=Arr::get($o->values,$loop->index)) ? $x : '['.__('NEW').']' }}" @readonly(! ($new ?? FALSE))>
3+
@foreach(old($o->name_lc,($new ?? FALSE) ? [NULL] : $o->tagValues($langtag)) as $values)
4+
<div class="col-12">
5+
@foreach($values as $value)
6+
@if(($edit ?? FALSE) && ! $o->is_rdn)
7+
<div class="input-group has-validation">
8+
<input type="text" @class(['form-control','is-invalid'=>($e=$errors->get($o->name_lc.'.'.$loop->index)),'mb-1','border-focus'=>($o->values->contains($value))]) name="{{ $o->name_lc }}[]" value="{{ $value }}" placeholder="{{ ! is_null($x=Arr::get($o->values,$loop->index)) ? $x : '['.__('NEW').']' }}" @readonly(! ($new ?? FALSE))>
159

16-
<div class="invalid-feedback pb-2">
17-
@if($e)
18-
{{ join('|',$e) }}
19-
@endif
20-
</div>
21-
</div>
22-
@else
23-
{{ $value }}
10+
<div class="invalid-feedback pb-2">
11+
@if($e)
12+
{{ join('|',$e) }}
2413
@endif
25-
@endforeach
14+
</div>
2615
</div>
27-
</div>
28-
</div>
16+
@else
17+
{{ $value }}
18+
@endif
19+
@endforeach
2920
</div>
3021
@endforeach
3122
</x-attribute.layout>

resources/views/components/attribute/objectclass.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!-- $o=Attribute::class -->
2-
<x-attribute.layout :edit="$edit" :new="$new" :o="$o">
2+
<x-attribute.layout :edit="$edit" :new="$new" :o="$o" :langtag="$langtag">
33
@foreach(old($o->name_lc,$o->values) as $value)
44
@if($edit)
5-
<x-attribute.widget.objectclass :o="$o" :edit="$edit" :new="$new" :loop="$loop" :value="$value"/>
5+
<x-attribute.widget.objectclass :o="$o" :edit="$edit" :new="$new" :loop="$loop" :value="$value" :langtag="$langtag"/>
66
@else
77
{{ $value }}
88
@if ($o->isStructural($value))

resources/views/components/attribute/password.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- @todo We are not handling redirect backs yet with updated passwords -->
22
<!-- $o=Password::class -->
3-
<x-attribute.layout :edit="$edit ?? FALSE" :new="$new ?? FALSE" :o="$o">
3+
<x-attribute.layout :edit="$edit ?? FALSE" :new="$new ?? FALSE" :o="$o" :langtag="$langtag">
44
@foreach($o->values_old as $value)
55
@if($edit)
66
<div class="input-group has-validation mb-3">

resources/views/components/attribute/widget/options.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<span class="p-0 m-0">
55
@if($o->is_rdn)
66
<br/>
7-
<span class="btn btn-sm btn-outline-focus mt-3" disabled><i class="fas fa-fw fa-exchange"></i> @lang('Rename')</span>
7+
<button class="btn btn-sm btn-outline-focus mt-3" disabled><i class="fas fa-fw fa-exchange"></i> @lang('Rename')</button>
88
@elseif($edit && $o->can_addvalues)
99
@switch(get_class($o))
1010
@case(JpegPhoto::class)

0 commit comments

Comments
 (0)