Skip to content

Commit e09ed7d

Browse files
authored
Merge pull request #11 from oooholdings/dev
Show field on Index, Detail and Preview
2 parents a459c96 + 4333d1a commit e09ed7d

21 files changed

+1047
-646
lines changed

dist/css/field.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/field.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
3. [Hide Toolbar Elements](#hide-toolbar-elements)
1616
4. [Customize Password Generation](#customize-password-generation)
1717
5. [Operation Base Filling](#operation-base-filling)
18-
6. [Other Methods](#other-methods)
18+
6. [Index and Detail View](#index-and-detail-view)
19+
7. [Other Methods](#other-methods)
1920
4. [Credits](#credits)
2021
5. [License](#license)
2122

@@ -228,6 +229,38 @@ public function fields()
228229
}
229230
```
230231

232+
### Index and Detail View
233+
234+
You can now show the value of your field on the index or detail pages, usually you wouldn't want to do this
235+
if you're using this field for passwords. But with other use-cases like tokens and such, this would be great.
236+
Since there's a detail field now, you can use this within the resource preview modal.
237+
238+
```php
239+
// in app/Nova/[Resource].php
240+
241+
use OutOfOffice\PasswordGenerator\PasswordGenerator;
242+
243+
public function fields()
244+
{
245+
return [
246+
247+
PasswordGenerator::make( 'Personal Access Token' )
248+
// Show the password as plain-text by default on the respective pages
249+
// These two methods work well with the others as they just show the password
250+
// on page load, you can use the other methods below for the styling
251+
->showValueOnDetail( bool $show = true )
252+
->showValueOnIndex( bool $show = true )
253+
// Hide the password with a blur effect on the respective pages
254+
->blurValueOnDetail( bool $show = true )
255+
->blurValueOnIndex( bool $show = true )
256+
// Hide the password with a set character on the respective pages
257+
->redactValueOnDetail( bool $redact = true, string $character = '•' )
258+
->redactValueOnIndex( bool $redact = true, string $character = '•' )
259+
260+
];
261+
}
262+
```
263+
231264
### Other Methods
232265

233266
Just a list of other miscellaneous methods to control smaller features.
Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,103 @@
11
<template>
22
<PanelItem :index="index"
3-
:field="{ name: field.name }" />
3+
:field="{ name: field.name }"
4+
class="ooo:password-generator">
5+
<template v-slot:value>
6+
<div v-if="showValueOnDetail || blurValueOnDetail || redactValueOnDetail"
7+
class="ooo:pg-value">
8+
<div v-if="hidden"
9+
class="top-0 left-0 inline-block font-mono mr-2"
10+
:class="[ blurValueOnDetail ? 'ooo:pg-value-blurred' : '' ]">
11+
{{ blurValueOnDetail ? fakeValue : dotValue }}
12+
</div>
13+
<div v-else
14+
class="top-0 left-0 inline-block font-mono mr-2">
15+
{{ field.value }}
16+
</div>
17+
18+
<div class="flex">
19+
<div v-if="!showValueOnDetail || blurValueOnDetail || redactValueOnDetail">
20+
<icon-show v-if="hidden && !hideShowPasswordToggle"
21+
class="h-4 w-4"
22+
v-tooltip="tooltips.showPassword.disabled"
23+
@click="showValue"></icon-show>
24+
<icon-hide v-else
25+
class="h-4 w-4"
26+
v-tooltip="tooltips.showPassword.enabled"
27+
@click="hideValue"></icon-hide>
28+
</div>
29+
30+
<icon-copy v-if="!hideCopyPasswordButton"
31+
class="h-4 w-4 ml-2"
32+
v-tooltip="tooltips.copyPassword.dynamic"
33+
@click="copyPassword"></icon-copy>
34+
</div>
35+
</div>
36+
<div v-else>&mdash;</div>
37+
</template>
38+
</PanelItem>
439
</template>
540

641
<script>
42+
import baseField from '../mixins/baseField';
43+
import hideIcon from './icons/hideIcon';
44+
import showIcon from './icons/showIcon';
45+
import copyIcon from './icons/copyIcon';
46+
747
export default {
8-
props: [ 'index', 'resource', 'resourceName', 'resourceId', 'field' ],
48+
mixins: [ baseField ],
49+
props: [ 'index', 'resource', 'resourceName', 'resourceId', 'field' ],
50+
components: {
51+
'icon-copy': copyIcon,
52+
'icon-hide': hideIcon,
53+
'icon-show': showIcon,
54+
},
55+
data() {
56+
return {
57+
hidden: !this.field.showValueOnDetail,
58+
};
59+
},
60+
mounted() {
61+
console.log( this.field );
62+
},
63+
methods: {
64+
showValue() {
65+
this.hidden = false;
66+
},
67+
hideValue() {
68+
this.hidden = true;
69+
},
70+
toggleValueVisibility() {
71+
this.hidden = !this.hidden;
72+
},
73+
copyPassword() {
74+
if ( this.field.value !== '' ) {
75+
if ( navigator.clipboard && window.isSecureContext ) {
76+
navigator.clipboard.writeText( this.field.value );
77+
Nova.success( 'Password has been copied.' );
78+
} else {
79+
let textArea = document.createElement( 'textarea' );
80+
textArea.value = this.field.value;
81+
82+
textArea.style.top = '-9999px';
83+
textArea.style.left = '-9999px';
84+
textArea.style.position = 'fixed';
85+
86+
document.body.appendChild( textArea );
87+
textArea.focus();
88+
textArea.select();
89+
90+
return new Promise( ( res, rej ) => {
91+
document.execCommand( 'copy' ) ? res() : rej();
92+
Nova.success( 'Password has been copied.' );
93+
94+
textArea.remove();
95+
} );
96+
}
97+
} else {
98+
Nova.error( 'No password to copy, type or generate a password.' );
99+
}
100+
},
101+
}
9102
}
10103
</script>

0 commit comments

Comments
 (0)