Friday, 23 December 2016
Friday, 16 December 2016
DropZone Js with ajax & Multiple photo and file upload functionality
HTML=======>
%form.uploadform.dropzone.no-margin.dz-clickable{:action => ""} .dz-default.dz-message %span Drop your Cover Picture here .event_photo_upload_btn#event_photo_upload_btn Upload
JAVASCRIPT====>>
Dropzone.autoDiscover = false; // keep this line if you have multiple dropzones in the same page
$(".uploadform").dropzone({ autoProcessQueue: false, // To stop auto upload acceptedFiles: "image/jpeg", url: 'file_photo_upload', //maxFiles: 1, // Number of files at a time //maxFilesize: 1, //in MB maxfilesexceeded: function(file) { alert('You have uploaded more than 1 Image. Only the first file will be uploaded!'); }, init: function () { var submitButton = document.querySelector("#event_photo_upload_btn") myDropzone = this; // closure
submitButton.addEventListener("click", function() { //var status_message = $("#status_txtbox_post").val().trim(); var files = myDropzone.files.length; console.log("No of files ="+files); if(files > 0){ myDropzone.processQueue(); // To upload files }else{ $("#my-dropzone").attr('style','border-color:red !important'); } });
this.on("sending", function(file, xhr, data) { var event_id = $("#event_id").val();
data.append("attachable_id", event_id); data.append("event_id", event_id); data.append("trip_id", trip_id); data.append("isPhoto", true); data.append("isDoc", false); data.append("attachable_type", 'DailyItinerary'); }); }, success: function (response) { var x = JSON.parse(response.xhr.responseText); $('.icon').hide(); // Hide Cloud icon //$('#uploader').modal('hide'); // On successful upload hide the modal window $('.img').attr('src',x.img); // Set src for the image $('.thumb').attr('src',x.thumb); // Set src for the thumbnail $('img').addClass('imgdecoration'); //this.removeAllFiles(); // This removes all files after upload to reset dropzone for next upload console.log('Image -> '+x.img+', Thumb -> '+x.thumb); // Just to return the JSON to the console. }, addRemoveLinks: true, removedfile: function(file) { var _ref; // Remove file on clicking the 'Remove file' button return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0; }});
Wednesday, 14 December 2016
PHP Laravel start with project
composer create-project --prefer-dist laravel/laravel blog
New project for particular version ====>
composer create-project laravel/laravel=4.1.27 your-project-name --prefer-dist
2) Create database connection ==>
update details in project/.env file
3) After Create Auth by:
php artisan make:auth
php artisan migrate
php artisan config:cache
4) Resister a user & login
5)
Tuesday, 13 December 2016
Sub Drop-Down bolck Bootstrap
<!-- Styles -->
<style>
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #ccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #fff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
-webkit-border-radius: 6px 0 6px 6px;
-moz-border-radius: 6px 0 6px 6px;
border-radius: 6px 0 6px 6px;
}
</style>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Main
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Login
</a>
</li>
<li class="dropdown-submenu">
<a href="#">Even More..</a>
<ul class="dropdown-menu">
<li><a href="#">3rd level</a></li>
<li class="dropdown-submenu">
<a href="#">Even More..</a>
<ul class="dropdown-menu">
<li><a href="#">4rd level</a></li>
<li class="dropdown-submenu">
<a href="#">Even More..</a>
<ul class="dropdown-menu">
<li><a href="#">5rd level</a></li>
<li><a href="#">5rd level</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
N level looping in logic
Create Table : Menu : id,name,parent_id
function parseTree($menu, $root = null) {
$return = array();
# Traverse the tree and search for direct children of the root
foreach($menu as $child => $parent) {
# A direct child is found
if($parent->parent_id == $root) {
# Remove item from tree (we don't need to traverse this again)
unset($menu[$child]);
# Append the child into result array and parse its children
$return[] = array(
'name' => $parent,
'children' => $this->parseTree($menu, $child)
);
}
}
return empty($return) ? null : $return;
}
function printParent($tree){
if(!is_null($tree) && count($tree) > 0) {
echo '<ul>';
foreach($tree as $node) {
// print_r($node);exit;
echo '<li>'.$node['name']['name'];
$this->printParent($node['children']);
echo '</li>';
}
echo '</ul>';
}
}
OR=======================
public function index()
{
$allMenu = Menu::all();
$childe_parent_menu_list = array();
foreach($allMenu as $menu){
$childe_parent_menu_list[$menu->id] = $menu;
}
$menu_tree = array();
$menu_tree = $this->parseTree($childe_parent_menu_list);
$html_view = '';
$html_view = $this->printParent($menu_tree,$html_view);
return view('Menu.index',array('menus'=>$allMenu,'menu_tree'=>$html_view));
}
function parseTree($menu, $root = null) {
$return = array();
# Traverse the tree and search for direct children of the root
foreach($menu as $child => $parent) {
# A direct child is found
if($parent->parent_id == $root) {
# Remove item from tree (we don't need to traverse this again)
unset($menu[$child]);
# Append the child into result array and parse its children
$return[] = array(
'name' => $parent,
'children' => $this->parseTree($menu, $child)
);
}
}
return empty($return) ? null : $return;
}
function printParent($tree,$html_view=NULL){
$html_view = '';
if(!is_null($tree) && count($tree) > 0) {
$html_view .= '<ul>';
foreach($tree as $node) {
// print_r($node);exit;
$html_view .= '<li>'.$node['name']['name'];
$html_view .=$this->printParent($node['children'],$html_view);
$html_view .= '</li>';
}
$html_view .= '</ul>';
}
//print_r( $html_view);exit;
return $html_view;
}
function parseTree($menu, $root = null) {
$return = array();
# Traverse the tree and search for direct children of the root
foreach($menu as $child => $parent) {
# A direct child is found
if($parent->parent_id == $root) {
# Remove item from tree (we don't need to traverse this again)
unset($menu[$child]);
# Append the child into result array and parse its children
$return[] = array(
'name' => $parent,
'children' => $this->parseTree($menu, $child)
);
}
}
return empty($return) ? null : $return;
}
function printParent($tree){
if(!is_null($tree) && count($tree) > 0) {
echo '<ul>';
foreach($tree as $node) {
// print_r($node);exit;
echo '<li>'.$node['name']['name'];
$this->printParent($node['children']);
echo '</li>';
}
echo '</ul>';
}
}
OR=======================
public function index()
{
$allMenu = Menu::all();
$childe_parent_menu_list = array();
foreach($allMenu as $menu){
$childe_parent_menu_list[$menu->id] = $menu;
}
$menu_tree = array();
$menu_tree = $this->parseTree($childe_parent_menu_list);
$html_view = '';
$html_view = $this->printParent($menu_tree,$html_view);
return view('Menu.index',array('menus'=>$allMenu,'menu_tree'=>$html_view));
}
function parseTree($menu, $root = null) {
$return = array();
# Traverse the tree and search for direct children of the root
foreach($menu as $child => $parent) {
# A direct child is found
if($parent->parent_id == $root) {
# Remove item from tree (we don't need to traverse this again)
unset($menu[$child]);
# Append the child into result array and parse its children
$return[] = array(
'name' => $parent,
'children' => $this->parseTree($menu, $child)
);
}
}
return empty($return) ? null : $return;
}
function printParent($tree,$html_view=NULL){
$html_view = '';
if(!is_null($tree) && count($tree) > 0) {
$html_view .= '<ul>';
foreach($tree as $node) {
// print_r($node);exit;
$html_view .= '<li>'.$node['name']['name'];
$html_view .=$this->printParent($node['children'],$html_view);
$html_view .= '</li>';
}
$html_view .= '</ul>';
}
//print_r( $html_view);exit;
return $html_view;
}
Friday, 9 December 2016
Create every day log file in rails
/etc/logrotate. conf
OR
I try down one but i face issue when starting serve :
http://blog.teksol.info/2007/06/13/how-to-set-logger-options-in-rails
How to set logger options in Rails
2007-06-14
Today, I was replacing RailsCron and BackgrounDRb with generated Daemons, and I happened to investigate how Rails sets up it’s logger. For the longest time, I knew it was possible to change the options, but I just never investigated how to do it. I thought I’d share my findings so others won’t be in the dark as I was.
Actually doing the replacement is very easy:
config/environment.rb
1 Rails::Initializer.run do |config| 2 config.logger = Logger.new(File.dirname(__FILE__) + "/../log/#{RAILS_ENV}.log") 3 end
That’s it. Have fun. Stop reading… Unless you want more details.
This is essentially what Rails does, except now you have complete control over how theLogger is instantiated.
Some options you might want to investigate:
1 # Keep at most 2 2 megabytes log files 2 config.logger = Logger.new(File.dirname(__FILE__) + "/../log/#{RAILS_ENV}.log", 2, 2*1024*1024) 3 4 # Create a new log file each day 5 config.logger = Logger.new(File.dirname(__FILE__) + "/../log/#{RAILS_ENV}.log", "daily")
If you are running a script which loads the Rails environment manually, you can also do this:
lib/daemons/futures_worker.rb
1 #!/usr/bin/env ruby 2 3 # You might want to change this 4 raise "No RAILS_ENV defined" if ENV["RAILS_ENV"].to_s.empty? 5 6 require "logger" 7 8 RAILS_DEFAULT_LOGGER = Logger.new(File.dirname(__FILE__) + "/../../log/futures_runner.rb.log", 3, 2*1024*1024) 9 require File.dirname(__FILE__) + "/../../config/environment" 10 11 # Other code as appropriate
The
Rails::Initializer is smart enough to use either the RAILS_DEFAULT_LOGGER or the one defined in the configuration block. For the gory details, please read Rails::Initializer#initialize_logger
Subscribe to:
Posts (Atom)