Skip to content

Commit

Permalink
Merge pull request #1 from ramonfeleus/readonly-translated
Browse files Browse the repository at this point in the history
  • Loading branch information
gldrenthe89 authored Jun 11, 2021
2 parents a75c3c5 + 2982584 commit 481559c
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 28 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,16 @@ NovaGenerateString::make('String')
NovaGeneratePassword::make('password'), // possible options are the same as above
```

## Localization

The translation file(s) can be published by using the following publish command:

```bash
php artisan vendor:publish --provider="Gldrenthe89\NovaStringGeneratorField\NovaStringGeneratorFieldServiceProvider" --tag="translations"
```

You can add your translations to `resources/lang/vendor/nova-string-generator-field/` by creating a new translations file with the locale name (ie `et.json`) and copying the JSON from the existing `en.json`.


## License:
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"require": {
"php": ">=7.1.0",
"laravel/nova": "~3.0",
"illuminate/support": "^7.0|^8.0"
"illuminate/support": "^7.0|^8.0",
"optimistdigital/nova-translations-loader": "^3.0.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions resources/js/components/Form/PasswordGeneratorField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<div class="my-auto ml-3 cursor-pointer" v-on:click="switchVisibility();">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" :id="field.attribute.concat('VisibilityButton')" fill="#bacad6"><path d="M15 12c0 1.654-1.346 3-3 3s-3-1.346-3-3 1.346-3 3-3 3 1.346 3 3zm9-.449s-4.252 8.449-11.985 8.449c-7.18 0-12.015-8.449-12.015-8.449s4.446-7.551 12.015-7.551c7.694 0 11.985 7.551 11.985 7.551zm-7 .449c0-2.757-2.243-5-5-5s-5 2.243-5 5 2.243 5 5 5 5-2.243 5-5z"/></svg>
</div>
<input type="button" class="btn btn-default btn-primary ml-3 cursor-pointer" value="Generate" :id="field.attribute.concat('GenerateButton')" v-on:click="generatePassword();">
<input type="button" class="btn btn-default btn-icon ml-3 cursor-pointer" value="Copy" :id="field.attribute.concat('CopyButton')" disabled="disabled" v-on:click="copyPassword();">
<input v-if="!isReadonly" type="button" class="btn btn-default btn-primary ml-3 cursor-pointer" v-bind:value="__('Generate')" :id="field.attribute.concat('GenerateButton')" v-on:click="generatePassword();">
<input type="button" class="btn btn-default btn-icon ml-3 cursor-pointer" v-bind:value="__('Copy')" :id="field.attribute.concat('CopyButton')" :disabled="!copyEnabled()" v-on:click="copyPassword();">
</div>
</template>
</default-field>
Expand All @@ -36,6 +36,9 @@ export default {
},
methods: {
copyEnabled() {
return window.location.protocol === 'https:' && this.value.length > 0;
},
generatePassword() {
let chars = '';
if (this.field.exclude_rules && this.field.exclude_rules.length > 0){
Expand All @@ -46,7 +49,7 @@ export default {
&& this.field.exclude_rules.includes('numbers')
&& this.field.exclude_rules.includes('uppercase')
&& this.field.exclude_rules.includes('lowercase')){
alert('Include at least one characters type! Symbols, Numbers, Lowercase, Uppercase');
alert(this.__('Include at least one characters type! Symbols, Numbers, Lowercase, Uppercase'));
return false;
}
Expand Down Expand Up @@ -77,24 +80,20 @@ export default {
}
this.value = pass;
if (window.location.protocol === 'https:') {
document.getElementById(this.field.attribute.concat('CopyButton')).disabled = false;
}
let button = document.getElementById(this.field.attribute.concat('GenerateButton'));
button.value = 'Generated';
setTimeout(function () {
button.value = 'Regenerate'
button.value = this.__('Generated');
setTimeout(() => {
button.value = this.__('Regenerate');
}, 750);
},
copyPassword() {
let fieldText = document.getElementById(this.field.attribute);
let button = document.getElementById(this.field.attribute.concat('CopyButton'));
if (fieldText.value.length > 0) {
navigator.clipboard.writeText(fieldText.value);
button.value = "Copied";
setTimeout(function () {
button.value = 'Copy'
button.value = this.__('Copied');
setTimeout(() => {
button.value = this.__('Copy');
}, 750);
}
},
Expand Down
25 changes: 12 additions & 13 deletions resources/js/components/Form/StringGeneratorField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
:value="suggestion"
/>
</datalist>
<input type="button" class="btn btn-default btn-primary ml-3 cursor-pointer" value="Generate" :id="field.attribute.concat('GenerateButton')" v-on:click="generateString();">
<input type="button" class="btn btn-default btn-icon ml-3 cursor-pointer" value="Copy" :id="field.attribute.concat('CopyButton')" disabled="disabled" v-on:click="copyString();">
<input v-if="!isReadonly" type="button" class="btn btn-default btn-primary ml-3 cursor-pointer" v-bind:value="__('Generate')" :id="field.attribute.concat('GenerateButton')" v-on:click="generateString();">
<input type="button" class="btn btn-default btn-icon ml-3 cursor-pointer" v-bind:value="__('Copy')" :id="field.attribute.concat('CopyButton')" :disabled="!copyEnabled()" v-on:click="copyString();">
</div>
</template>
</default-field>
Expand Down Expand Up @@ -63,6 +63,9 @@ export default {
},
methods: {
copyEnabled() {
return window.location.protocol === 'https:' && this.value.length > 0;
},
generateString() {
let chars = '';
if (this.field.exclude_rules && this.field.exclude_rules.length > 0){
Expand All @@ -73,7 +76,7 @@ export default {
&& this.field.exclude_rules.includes('numbers')
&& this.field.exclude_rules.includes('uppercase')
&& this.field.exclude_rules.includes('lowercase')){
alert('Include at least one characters type! Symbols, Numbers, Lowercase, Uppercase');
alert(this.__('Include at least one characters type! Symbols, Numbers, Lowercase, Uppercase'));
return false;
}
Expand Down Expand Up @@ -104,24 +107,20 @@ export default {
}
this.value = string;
if (window.location.protocol === 'https:') {
document.getElementById(this.field.attribute.concat('CopyButton')).disabled = false;
}
let button = document.getElementById(this.field.attribute.concat('GenerateButton'));
button.value = 'Generated';
setTimeout(function () {
button.value = 'Regenerate'
button.value = this.__('Generated');
setTimeout(() => {
button.value = this.__('Regenerate');
}, 750);
},
copyString() {
let fieldText = document.getElementById(this.field.attribute);
let button = document.getElementById(this.field.attribute.concat('CopyButton'));
if (fieldText.value.length > 0) {
navigator.clipboard.writeText(fieldText.value);
button.value = "Copied";
setTimeout(function () {
button.value = 'Copy'
button.value = this.__('Copied');
setTimeout(() => {
button.value = this.__('Copy');
}, 750);
}
}
Expand Down
8 changes: 8 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Copied": "Copied",
"Copy": "Copy",
"Generate": "Generate",
"Generated": "Generated",
"Include at least one characters type! Symbols, Numbers, Lowercase, Uppercase": "Include at least one characters type! Symbols, Numbers, Lowercase, Uppercase",
"Regenerate": "Regenerate"
}
8 changes: 8 additions & 0 deletions resources/lang/nl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Copied": "Gekopieërd",
"Copy": "Kopieër",
"Generate": "Genereer",
"Generated": "Gegenereerd",
"Include at least one characters type! Symbols, Numbers, Lowercase, Uppercase": "Gebruik tenminste 1 karakter type: Symbolen, Nummers, Hoofdletters of kleine letters",
"Regenerate": "Genereer opnieuw"
}
4 changes: 4 additions & 0 deletions src/NovaStringGeneratorFieldServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use Illuminate\Support\ServiceProvider;
use Laravel\Nova\Events\ServingNova;
use Laravel\Nova\Nova;
use OptimistDigital\NovaTranslationsLoader\LoadsNovaTranslations;

class NovaStringGeneratorFieldServiceProvider extends ServiceProvider
{
use LoadsNovaTranslations;
/**
* Bootstrap any application services.
*
Expand All @@ -19,5 +21,7 @@ public function boot()
Nova::script('generate-string', __DIR__.'/../dist/js/field.js');
Nova::style('generate-string', __DIR__.'/../dist/css/field.css');
});

$this->loadTranslations(__DIR__ . '/../resources/lang', 'nova-string-generator-field', true);
}
}

0 comments on commit 481559c

Please sign in to comment.