Zero padding in front using Numeral.js and Aurelia - aurelia

I'm trying to build a basic Aurelia app.
Suppose I got a data where id = 1.
I can't seem to find a way to have 2 leading zero padding to my id using Numeral.js (http://numeraljs.com/).
I have this code:
<span>#${book.number | numberFormat:'000'}</span>
I was expecting an output like:
#001
but all I got was just
1
Ideally, it should go:
#001
#002
#003
...
#023
#024
#025
...
#135
#136
#137
etc
Does anyone know if this is possible ?

Thanks Stevies on Aurelia Gitter,
The solution is in the formatter class, we can go:
import numeral from 'numeral';
export class NumberFormatValueConverter {
toView(value) {
var output = new Intl.NumberFormat('en', {minimumIntegerDigits: 3, useGrouping: false}).format(value);
return output;
}
}

Related

Pluralization in vue i18n

Hi i am trying to pluralize based on https://kazupon.github.io/vue-i18n/guide/pluralization.html
imageCount== 1
? $t("message.imageMessage", 1, { imageCount})
: $t("message.imageMessage", imageCount, {
imageCount
})
imageMessage: '{imageCount} image downloaded | {imageCount} images downloaded'
Problem : currently it is displaying bo the messages which should not happen,is there anything wrong in the way which i have implemented?
Codesandbox: https://codesandbox.io/s/lingering-haze-z9jzt?file=/src/components/HelloWorld.vue
From the documentation...
Your template will need to use $tc() instead of $t().
You can also improve / shorten your code somewhat by using {n} or {count} in your translation strings...
en: {
message: {
imageMessage: "{n} image downloaded | {n} images downloaded"
}
}
and in your templates
$tc("message.imageMessage", imageCount)
With vue#3 and vue-i18n#9 and Composition API, with locale key being:
{
message: {
imageMessage: "no images | 1 image downloaded | {n} images downloaded"
}
}
It's enough to do:
$t('message.imageMessage', { n: images.length })
// OR
$t('message.imageMessage', images.length)

QGroupBox sizing with my QT5 custom widget

I am trying to make a custom widget: for displaying a processor register which has a name, a value and can be displayed in octal/decimal hexa. The code is shown at the bottom. I receive better result when I use the code as shown (i.e I insert QRadioButtons):
If I use
mainLayout->addWidget(DisplayMode);
instead (I guess this is the correct method) then the resulting picture is
Do I misunderstand something? What is wrong?
RegisterWidget::RegisterWidget(QWidget *parent)
:QFrame (parent)
{
mValue = 0;
mName = "";
setFrameStyle(QFrame::Panel | QFrame::Sunken);
QHBoxLayout *mainLayout = new QHBoxLayout(this);
label = new QLabel(tr("mName"),this);
label->setText(mName);
label->setLineWidth(2);
QGroupBox *DisplayMode = new QGroupBox("");
QRadioButton *OctalR = new QRadioButton(this);
QRadioButton *DecimalR = new QRadioButton(this);
DecimalR->setChecked(true); DecimalR->setDown(true);
QRadioButton *HexaR = new QRadioButton(this);
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addWidget(OctalR);
hbox->addWidget(DecimalR);
hbox->addWidget(HexaR);
hbox->addStretch(1);
DisplayMode->setLayout(hbox);
mainLayout->addWidget(label);
Value = new QLCDNumber(this);
Value->setDigitCount(8);
Value->setSegmentStyle(QLCDNumber::Flat);
Value->display(mValue);
mainLayout->addWidget(Value);
/* mainLayout->addWidget(DisplayMode);*/
mainLayout->addWidget(OctalR);
mainLayout->addWidget(DecimalR);
mainLayout->addWidget(HexaR);
setLineWidth(3);
setLayout(mainLayout);
connect(OctalR, SIGNAL(clicked()), this, SLOT(setOctal()));
connect(DecimalR, SIGNAL(clicked()), this, SLOT(setDecimal()));
connect(HexaR, SIGNAL(clicked()), this, SLOT(setHexa()));
}
Call QLayout::setContentsMargins() for both mainLayout and hbox. Try (3, 3, 3, 3) as parameters for a starting point and tweak. Layouts have default margins of 11 pixels on most platforms, according to the docs.

Dart splits long stdout data into two ProcessResult events

When listening to a long string output from a shell process, I receive the data in two chunks. How can I get the entire text?
Here is the code in question:
int i = 0;
Process.start('perl', ['print_text.pl']).then((Process p) {
p.stdout.transform(UTF8.decoder).listen((data) => print("${i++} ${data}"));
p.stdin.writeln('print');
});
The result from running this code is:
0 text.....
1 text.....
I've reported this issue as a bug here. You can run the sample app attached to the report to see the issue.
Try using UTF8.decodeStream().
import 'dart:io';
import 'dart:convert' show UTF8;
main() {
Process.start('ls', ['-la'])
.then((p) => UTF8.decodeStream(p.stdout))
.then((s) => print('Output:\n$s'));
}
I solved this problem by doing the following:
In the shell script, tag the start and the end of the shell's output with a random number.
In Dart, concatenate all the chunks together and use the tags to check if you got the complete result.
This solution does not require exiting the process to obtain the process result.
This is a sample code:
String text = '';
process.stdout.transform(UTF8.decoder).listen((String chunk) {
text = text + chunk;
if (text.substring(errors.length - 1) == text.substring(0, 1)) {
text = text.replaceFirst(new RegExp(r'^(\d+)'), '').replaceFirst(new RegExp(r'(\d+)$'), '');
// use process result then clear text value for subsequent process results
text = '';
}
});
It's not clear what the actual question is but I assume this is what you are looking for:
import 'dart:io';
import 'dart:convert' show UTF8;
void main() {
int i = 0;
String text = '';
Process.start('perl', ['analyze.pl']).then((p) {
p.stdout.transform(UTF8.decoder).listen((data) =>
text += data);
p.exitCode.then((_) => print(text));
});
}

Trying to get the Grails ldap-0.8.2 plugin to work for non-authentication searching of AD

I've been trying to get the ldap-0.8.2 or gldapo plugin to work with Grails 2.3.5 to perform a simple person search in AD. I'm not looking for authentication, just to build a person directory search form. I have close to a week now looking at old references to problems implementing this plugin and just can not seem to figure out what the right combination of fiery hoops to jump through are.
In BuildConfig.groovy I have:
compile ":ldap:0.8.2"
In Config.groovy I have:
import edu.fgcu.gtd.GldapoUser
ldap {
directories {
directory1 {
defaultDirectory = true
url = "ldap://FGCU-AMBERJACK.primary.ad.fgcu.edu"
userDn = "CN=******,OU=******,OU=******,OU=******,DC=**,DC=**,DC=***,DC=***"
password = "********"
searchControls {
countLimit = 40
timeLimit = 600
searchScope = "subtree"
}
}
}
schemas: [edu.fgcu.gtd.GldapoUser]
}
I have the following groovy file at path "Ldap/edu/fgcu/gtd/GldapoUser.groovy"
package edu.fgcu.gtd
import gldapo.schema.annotation.GldapoNamingAttribute
import gldapo.schema.annotation.GldapoSynonymFor
import gldapo.schema.annotation.GldapoSchemaFilter
/**
*
* #author pallen
*/
#GldapoSchemaFilter("(objectclass=person)")
class GldapoUser {
#GldapoSynonymFor("uid")
String username
#GldapoSynonymFor("cn")
String name
#GldapoSynonymFor("title")
String title
#GldapoSynonymFor("physicalDeliveryOfficeName")
String office
#GldapoSynonymFor("telephoneNumber")
String phone
#GldapoSynonymFor("mail")
String email
#GldapoSynonymFor("department")
String department
}
And then I have the following controller
package edu.fgcu.gtd
import edu.fgcu.gtd.GldapoUser
class PersonSearchController {
def index() {
render(view: "search")
}
def search() {
String searchString = params?.lastName + "*"
if (params.firstName){
searchString += "," + params.firstName + "*"
}
def List personSearchList = GldapoUser.findAll(
base: "OU=Florida Gulf Coast University,DC=primary,DC=ad,DC=fgcu,DC=edu") {
like "cn", searchString
}
respond personSearchList, model:[personSearchCount: personSearchList.count()]
}
}
When I run the application I receive the following error, which I have seen others reference, but none of the suggestions that I have found so far have helped me resolve this.
URI: /GroovyGTD/personSearch/search
Class: groovy.lang.MissingMethodException
Message: No signature of method: static edu.fgcu.gtd.GldapoUser.findAll() is applicable for argument types: (java.util.LinkedHashMap, edu.fgcu.gtd.PersonSearchController$_search_closure1) values: [[base:OU=Florida Gulf Coast University,DC=primary,DC=ad,DC=fgcu,DC=edu], ...] Possible solutions: findAll(), findAll(groovy.lang.Closure), find(), find(groovy.lang.Closure)
I'm relatively new to Grails, but am fairly adept with Java, and have worked through some difficult configurations for external libraries, but this plugin has me stumped.
Thanks in advance,
Paul
I was able to get it all to work.
First issue was the schemas comment. I had to put schemas = [ edu.fgcu.gtd.GldapoUser] in config.groovy.
Next I had to add a #GldapoNamingAttribute to my GldapoUser object for the "cn" attribute, and "uid" is not in my AD person entry so I got rid of it and used the "sAMAccountName" for username.
It is all working well after those few changes.

Store.reload() ->How to Query by lastParam in ExtJs4

I have a Grid.
Get Data Code
Code:
var myParam = {
typeId : 1,
xxxx : 'xxxx' //some else
}
grid.store.load(myParam);
When to do something such as time renovate
Code:
grid.store.reload();
But this lost param.
In ExtJs3 have a Config of LastParam .
How to do in Extjs4.
thanks.
use the proxy's extraParams config.
grid.store.getProxy().extraParams = myParam;
grid.store.load();
grid.store.reload();
This way the params will be sent until you modify the extra param again with code.