Best practice for string String in Ionic 3 - string

What is the best practice for storing all app Strings in Ionic 3. Should I created one data provider and store all strings as constants?

There are multiple ways.But I have chosen very simple approach here.That is, Just create a static class as shown below.
Note: I extracted below example from my working project.
Constant file:
Handlers.ts
export class Handlers {
static BUDGET_PAGE_TOTAL_HANDLER = "budget-page-total-handler";
static NEW_PROJECT_PAGE_BUDGET_HANDLER = "new-project-page-budget-handler";
static HOME_PAGE_TRANSACTION_HANDLER = "home-page-transaction-handler";
}
Use like this:
.ts
import { Handlers } from '../../constants/Handlers';
eventHandlers() {
this.events.subscribe(Handlers.HOME_PAGE_TRANSACTION_HANDLER, this.transactionHandler);
}

Related

ABP does not automatically use custom mapper class

I have created a custom mapper class as below but ABP does not automatically register and use it while mapping.
https://docs.abp.io/en/abp/4.4/Object-To-Object-Mapping#iobjectmapper-tsource-tdestination-interface
Sorry for less detail, i have added some below,
I have found that mycustommapperclass's interface different from my object mapper,
should I implement for all container types?
public class HierachyItemCustomMapper : IObjectMapper<HierachyItem, HierachyItemDto>, ITransientDependency
{
and my usage like
var nodeListDto = ObjectMapper.Map<IEnumerable<HierachyItem>, IEnumerable<HierachyItemDto>>(nodeList);
How can i handle this?
Obviously I am looking for a result instead of foreach iterator loop.
Edit:
it have found that it is known issue as below
https://github.com/abpframework/abp/issues/94
I've tried just before and it seems it works as expected.
This is my HierachyItemCustomMapper class which I've created in the Application layer. (It should be created in the Application layer.)
public class HierachyItemCustomMapper : IObjectMapper<HierachyItem, HierachyItemDto>, ITransientDependency
{
public HierachyItemDto Map(HierachyItem source)
{
return new HierachyItemDto
{
Name = source.Name
};
}
public HierachyItemDto Map(HierachyItem source, HierachyItemDto destination)
{
destination.Name = source.Name;
return destination;
}
}
I've just added a property named Name in my both classes (HierachyItem and HierachyItemDto) to test.
You probably didn't define it in the Application layer and that cause the problem. Can you check it?
It's simple , your defination is wrong
it should be like that
public class HierachyItemCustomMapper : IObjectMapper<IEnumerable<HierachyItem>,
IEnumerable<HierachyItemDto>>, ITransientDependency {}
as it searches for exact defination match , and if you want to add also capability of using ObjectMapper.Map<HierachyItem, HierachyItemDto>
you can make your custom mapper defination like that
public class HierachyItemCustomMapper : IObjectMapper<IEnumerable<HierachyItem>,
IEnumerable<HierachyItemDto>>, IObjectMapper<HierachyItem, HierachyItemDto> ,
ITransientDependency {}
and you will implement both
good luck

Laravel export to excel - download issue

I can't generate xlsx file. I'am using maatwebsite/excel 3.1. I have installed it via this:
composer require maatwebsite/excel
I've added 'Excel' => Maatwebsite\Excel\Facades\Excel::class, to Aliases and Maatwebsite\Excel\ExcelServiceProvider::class, to providers.
I have structure of project like ProjectName->app->Exports.
<?php
namespace App\Exports;
use App\Order;
use App\Status;
use App\User;
use Maatwebsite\Excel\Concerns\FromCollection;
class ActiveOrderExport implements FromCollection
{
public function collection()
{
return Status::all();
}
}
In repository I have function excel, also with these inclusions:
use App\Exports\ActiveOrderExport;
use Maatwebsite\Excel\Facades\Excel;
public function excel()
{
return Excel::download(new ActiveOrderExport(), 'activeOrders.xlsx');
}
Route:Route::get('/export_excel', 'HomeController#excel')->name('admin.export_excel.excel');
Home Controller:
{
$this->AOrepository->excel();
//return back();
}
My problem is that no error is shown, only blank page. No download is executed in the browser.
I've watched several tutorials, I haven't noticed any important diffrence among the codes.
Can you help me please?

Static data initialised twice due to typo in import in TypeScript

I have a newbie question on TypeScript imports. I tried to make a class which holds some data in a static variable, and the data is lazily initialised in getInstance() method.
myStaticClass.ts:
class MyData {
x = 1;
}
export class MyStaticClass {
private static data: MyData;
static getInstance() {
if (MyStaticClass.data == null) {
console.log('data is null, initialising');
MyStaticClass.data = new MyData();
}
return MyStaticClass.data;
}
}
I imported this class in 2 other classes:
a.ts
import { MyStaticClass } from './MyStaticClass';
// NOTE the typo above - uppercase file name
export class A {
logX() {
console.log(MyStaticClass.getInstance().x);
}
}
index.ts
import { MyStaticClass } from './myStaticClass';
import { A } from './a';
console.log(MyStaticClass.getInstance().x);
new A().logX();
To my surprise, the output of ts-node index.ts is
data is null, initialising
1
data is null, initialising
1
If I correct the import the output is as expected - data is initialised only once.
I also checked that I get one initialisation for one variant of spelling (added 3rd class with another letter in upperCase)
Can anyone explain why this behaviour is in place?
(Additionally, what tools / debug statements I could have used to identify what is happening?)
Can I force TypeScript to flag this as error?
I am on MacOs, TS 3.6.3, node-ts 8.4.1
While on Windows two differently cased file names always point to the same file, on other platforms they do not. This means that imports with different file names are treated as different modules, this is by design and is not considered an issue (see here for node discussion)
The simple solution is to force consistent file casing to be used when importing modules. Typescript does have a compiler option to force this named forceConsistentCasingInFileNames (See docs). This option should prevent such issues.

Revit Api Load Command - Auto Reload

I'm working with the revit api, and one of its problems is that it locks the .dll once the command's run. You have to exit revit before the command can be rebuilt, very time consuming.
After some research, I came across this post on GitHub, that streams the command .dll into memory, thus hiding it from Revit. Letting you rebuild the VS project as much as you like.
The AutoReload Class impliments the revit IExteneralCommand Class which is the link into the Revit Program.
But the AutoReload class hides the actual source DLL from revit. So revit can't lock the DLL and lets one rebuilt the source file.
Only problem is I cant figure out how to implement it, and have revit execute the command. I guess my C# general knowledge is still too limited.
I created an entry in the RevitAddin.addin manifest that points to the AutoReload Method command, but nothing happens.
I've tried to follow all the comments in the posted code, but nothing seems to work; and no luck finding a contact for the developer.
Found at: https://gist.github.com/6084730.git
using System;
namespace Mine
{
// helper class
public class PluginData
{
public DateTime _creation_time;
public Autodesk.Revit.UI.IExternalCommand _instance;
public PluginData(Autodesk.Revit.UI.IExternalCommand instance)
{
_instance = instance;
}
}
//
// Base class for auto-reloading external commands that reside in other dll's
// (that Revit never knows about, and therefore cannot lock)
//
public class AutoReload : Autodesk.Revit.UI.IExternalCommand
{
// keep a static dictionary of loaded modules (so the data persists between calls to Execute)
static System.Collections.Generic.Dictionary<string, PluginData> _dictionary;
String _path; // to the dll
String _class_full_name;
public AutoReload(String path, String class_full_name)
{
if (_dictionary == null)
{
_dictionary = new System.Collections.Generic.Dictionary<string, PluginData>();
}
if (!_dictionary.ContainsKey(class_full_name))
{
PluginData data = new PluginData(null);
_dictionary.Add(class_full_name, data);
}
_path = path;
_class_full_name = class_full_name;
}
public Autodesk.Revit.UI.Result Execute(
Autodesk.Revit.UI.ExternalCommandData commandData,
ref string message,
Autodesk.Revit.DB.ElementSet elements)
{
PluginData data = _dictionary[_class_full_name];
DateTime creation_time = new System.IO.FileInfo(_path).LastWriteTime;
if (creation_time.CompareTo(data._creation_time) > 0)
{
// dll file has been modified, or this is the first time we execute this command.
data._creation_time = creation_time;
byte[] assembly_bytes = System.IO.File.ReadAllBytes(_path);
System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(assembly_bytes);
foreach (Type type in assembly.GetTypes())
{
if (type.IsClass && type.FullName == _class_full_name)
{
data._instance = Activator.CreateInstance(type) as Autodesk.Revit.UI.IExternalCommand;
break;
}
}
}
// now actually call the command
return data._instance.Execute(commandData, ref message, elements);
}
}
//
// Derive a class from AutoReload for every auto-reloadable command. Hardcode the path
// to the dll and the full name of the IExternalCommand class in the constructor of the base class.
//
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class AutoReloadExample : AutoReload
{
public AutoReloadExample()
: base("C:\\revit2014plugins\\ExampleCommand.dll", "Mine.ExampleCommand")
{
}
}
}
There is an easier approach: Add-in Manager
Go to Revit Developer Center and download the Revit SDK, unzip/install it, the check at \Revit 2016 SDK\Add-In Manager folder. With this tool you can load/reload DLLs without having to modify your code.
There is also some additional information at this blog post.
this is how you can use the above code:
Create a new VS class project; name it anything (eg. AutoLoad)
Copy&Paste the above code in-between the namespace region
reference revitapi.dll & revitapiui.dll
Scroll down to AutoReloadExample class and replace the path to point
your dll
Replace "Mine.ExampleCommand" with your plugins namespace.mainclass
Build the solution
Create an .addin manifest to point this new loader (eg.
AutoLoad.dll)
your .addin should include "FullClassName" AutoLoad.AutoReloadExample
This method uses reflection to create an instance of your plugin and prevent Revit to lock your dll file! You can add more of your commands just by adding new classes like AutoReloadExample and point them with seperate .addin files.
Cheers

using a common layout for several modules in Yii

I am using Yii framework in my web project. now, I have several modules and I want to use only one layout for all modules. I have used following codes for determining the layout for every controller/action in each module:
$this->layoutPath = Yii::getPathOfAlias('application.views.layouts');
$this->layout = '//layouts/myLayout';
Is there any other solution to do this by using same code in init() function of each module?
in other word, I have to write the above 2-line code in each action and i think it's not good and i want to reduce my number of lines of codes. for example as follows:
class StaffModule extends CWebModule
{
public $layout;
public $layoutPath;
public function init()
{
$this->layoutPath = Yii::getPathOfAlias('application.views.layouts');
$this->layout = '//layouts/myLayout';
$this->setImport(array(
'staff.models.*',
'staff.components.*',
));
}
}
but it doesn't work. Help me please.
Just use
$this->layout='//layouts/myLayout';
without
$this->layoutPath = Yii::getPathOfAlias('application.views.layouts');
because // mean you specific absolute path from root
The approach you are having in init function is in the right direction..I think the problem could be.. as you are defining layoutPath you shouldn't have //layouts..
$this->layoutPath = Yii::getPathOfAlias('application.views.layouts');
$this->layout = 'myLayout';
and you don't need these:
public $layout;
public $layoutPath;
I've answered similar question on
using common layout for several modules
The solution is set the layout on beforeControllerAction in your module.
It should work.

Resources