Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Romain Courteaud
slapos.core
Commits
4b8c8371
Commit
4b8c8371
authored
Jun 05, 2012
by
Thomas Lechauve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix infinite loop while route is unknown
parent
7f42bc1b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
23 deletions
+103
-23
jquery.urlJS/src/jquery.urljs.js
jquery.urlJS/src/jquery.urljs.js
+31
-3
jquery.urlJS/test/jquery.urljs_test.js
jquery.urlJS/test/jquery.urljs_test.js
+22
-7
vifib/index.html
vifib/index.html
+4
-0
vifib/static/js/core.js
vifib/static/js/core.js
+15
-10
vifib/static/js/jquery.urljs.js
vifib/static/js/jquery.urljs.js
+31
-3
No files found.
jquery.urlJS/src/jquery.urljs.js
View file @
4b8c8371
...
...
@@ -23,7 +23,20 @@ $.extend({
},
},
i
=
this
.
list
[
level
].
length
;
this
.
list
[
level
][
i
]
=
r
;
if
(
this
.
exist
(
r
)
===
false
)
{
this
.
list
[
level
][
i
]
=
r
;
}
},
exist
:
function
(
r
)
{
var
found
=
false
,
i
=
0
;
while
(
i
<
this
.
list
[
r
.
level
].
length
&&
found
===
false
)
{
if
(
this
.
list
[
r
.
level
][
i
].
route
===
r
.
route
)
{
found
=
true
;
}
i
+=
1
;
}
return
found
;
},
clean
:
function
(
level
)
{
...
...
@@ -34,14 +47,16 @@ $.extend({
this
.
list
=
this
.
list
.
slice
(
0
,
0
);
},
search
:
function
(
hash
)
{
search
:
function
(
hash
,
level
)
{
var
stop
=
false
,
i
,
j
,
regex
,
result
,
extracted
;
level
=
level
||
0
;
i
=
this
.
list
.
length
-
1
;
while
((
stop
===
false
)
&&
(
i
>=
0
))
{
hash
.
route
=
hash
.
route
===
"
undefined
"
?
"
/
"
:
hash
.
route
;
while
((
stop
===
false
)
&&
(
i
>=
level
))
{
j
=
0
;
while
((
stop
===
false
)
&&
(
j
<
this
.
list
[
i
].
length
))
{
extracted
=
$
.
router
.
extractKeys
(
this
.
list
[
i
][
j
].
route
);
...
...
@@ -54,12 +69,25 @@ $.extend({
hash
[
extracted
.
keys
[
k
]]
=
result
[
k
];
}
this
.
current
=
this
.
list
[
i
][
j
];
this
.
clean
(
this
.
list
[
i
][
j
].
level
+
1
);
console
.
log
(
this
.
list
[
i
][
j
].
route
)
this
.
list
[
i
][
j
].
callback
(
hash
);
}
j
+=
1
;
}
i
-=
1
;
}
},
isLastLevel
:
function
()
{
return
this
.
current
.
level
===
(
this
.
list
.
length
-
1
);
}
},
start
:
function
(
hash
,
level
)
{
var
hashInfo
=
this
.
parseHash
(
hash
);
if
(
$
.
router
.
routes
.
current
.
route
!==
hashInfo
.
route
)
{
this
.
routes
.
search
(
hashInfo
,
level
);
}
},
...
...
jquery.urlJS/test/jquery.urljs_test.js
View file @
4b8c8371
...
...
@@ -36,6 +36,7 @@ $(function () {
equal
(
$
.
router
.
routes
.
list
.
length
,
0
,
'
should remove all routes
'
);
});
module
(
'
search tests
'
,
{
teardown
:
function
()
{
$
.
router
.
routes
.
cleanAll
();
...
...
@@ -43,24 +44,23 @@ $(function () {
});
test
(
'
search test
'
,
function
()
{
var
url1
=
{
'
route
'
:
'
#
/new/path
'
,
'
param1
'
:
'
foo1
'
,
'
param2
'
:
'
foo2
'
,
'
filter
'
:
true
},
url2
=
{
'
route
'
:
'
#
/new/path/1
'
,
'
param1
'
:
'
foo1
'
},
url3
=
{
'
route
'
:
'
#
/new/path/1/foo
'
,
'
param1
'
:
'
foo1
'
},
var
url1
=
{
'
route
'
:
'
/new/path
'
,
'
param1
'
:
'
foo1
'
,
'
param2
'
:
'
foo2
'
,
'
filter
'
:
true
},
url2
=
{
'
route
'
:
'
/new/path/1
'
,
'
param1
'
:
'
foo1
'
},
url3
=
{
'
route
'
:
'
/new/path/1/foo
'
,
'
param1
'
:
'
foo1
'
},
spy
=
sinon
.
spy
();
$
.
router
.
routes
.
add
(
'
#/new/path
'
,
0
,
spy
);
$
.
router
.
routes
.
add
(
'
#/new/path/:id
'
,
1
,
spy
);
$
.
router
.
routes
.
add
(
'
#/new/path/:id/:other
'
,
2
,
spy
);
$
.
router
.
routes
.
add
(
'
/new/path
'
,
0
,
spy
);
$
.
router
.
routes
.
search
(
url1
);
delete
url1
.
route
;
ok
(
spy
.
calledWith
(
url1
));
$
.
router
.
routes
.
add
(
'
/new/path/:id
'
,
1
,
spy
);
$
.
router
.
routes
.
search
(
url2
);
delete
url2
.
route
;
$
.
extend
(
url2
,
{
'
id
'
:
'
1
'
});
ok
(
spy
.
calledWith
(
url2
));
$
.
router
.
routes
.
add
(
'
/new/path/:id/:other
'
,
2
,
spy
);
$
.
router
.
routes
.
search
(
url3
);
delete
url3
.
route
;
$
.
extend
(
url3
,
{
'
id
'
:
'
1
'
,
'
other
'
:
'
foo
'
});
...
...
@@ -68,6 +68,19 @@ $(function () {
ok
(
spy
.
calledThrice
);
});
test
(
'
avoid loop test
'
,
function
()
{
var
spy
=
sinon
.
spy
(),
i
=
0
,
callback
=
function
(
params
)
{
console
.
log
(
params
)
$
.
router
.
routes
.
add
(
'
/first
'
,
1
,
spy
)
$
.
router
.
start
(
params
.
route
);
}
$
.
router
.
routes
.
add
(
'
/
'
,
0
,
callback
);
$
.
router
.
routes
.
search
({
'
route
'
:
'
/first
'
});
ok
(
spy
.
calledOnce
);
});
module
(
'
router methods tests
'
,
{
});
...
...
@@ -103,4 +116,6 @@ $(function () {
deepEqual
(
response
,
urls
[
url
]);
}
});
});
vifib/index.html
View file @
4b8c8371
...
...
@@ -282,6 +282,10 @@
<
/div
>
</script>
<script
id=
"topbar"
type=
"text/html"
>
</script>
<script
id=
"root"
type=
"text/html"
>
<
div
id
=
"
loading
"
style
=
"
position: absolute; right: 20px; top: 20px;
"
><
/div
>
<
div
class
=
"
navbar
"
>
...
...
vifib/static/js/core.js
View file @
4b8c8371
...
...
@@ -54,9 +54,9 @@
}
$
(
this
).
vifib
(
'
popup
'
,
message
);
},
spinOptions
=
{
color
:
"
#FFFFFF
"
,
lines
:
30
,
length
:
0
,
width
:
5
,
radius
:
7
,
rotate
:
0
,
trail
:
60
,
speed
:
1.6
},
methods
=
{
init
:
function
()
{
var
routes
=
[[[
'
/
'
,
methods
[
'
showRoot
'
]]]];
...
...
@@ -94,6 +94,9 @@
nextLevel
=
route
.
level
+
1
;
$
(
this
).
vifib
(
'
render
'
,
'
root
'
);
$
.
router
.
routes
.
add
(
'
/catalog
'
,
nextLevel
,
methods
.
showCatalog
,
$
(
"
#main
"
));
$
.
router
.
routes
.
add
(
'
/dashboard
'
,
nextLevel
,
methods
.
showDashboard
,
$
(
"
#main
"
));
// default page
$
.
router
.
start
(
params
.
route
,
nextLevel
);
},
genInstanceUrl
:
function
(
uri
)
{
...
...
@@ -103,7 +106,7 @@
extractInstanceURIFromHref
:
function
()
{
return
decodeURIComponent
(
$
(
this
).
attr
(
'
href
'
).
split
(
'
/
'
).
pop
());
},
extractInstanceURIFromHashtag
:
function
()
{
var
loc
=
window
.
location
.
href
.
split
(
'
#
'
)[
1
].
split
(
'
/
'
),
i
=
$
.
inArray
(
"
instance
"
,
loc
);
...
...
@@ -149,15 +152,14 @@
$
(
this
).
vifib
(
'
render
'
,
'
catalog.all
'
);
for
(
i
=
0
;
i
<
14
;
i
++
)
{
item
=
$
(
this
).
vifib
(
'
getRender
'
,
'
catalog.item
'
);
console
.
log
(
item
)
$
(
"
#catalog-all
"
).
append
(
item
);
}
});
},
showCatalog
:
function
()
{
showCatalog
:
function
(
params
)
{
return
this
.
each
(
function
()
{
var
i
,
item
;
var
i
,
item
,
nextLevel
;
$
(
this
).
vifib
(
'
render
'
,
'
catalog.preview
'
);
for
(
i
=
0
;
i
<
2
;
i
++
)
{
item
=
$
(
this
).
vifib
(
'
getRender
'
,
'
catalog.item
'
);
...
...
@@ -171,6 +173,9 @@
item
=
$
(
this
).
vifib
(
'
getRender
'
,
'
catalog.categorie
'
);
$
(
"
#catalog-categories
"
).
append
(
item
);
}
nextLevel
=
$
.
router
.
routes
.
current
.
level
+
1
;
$
.
router
.
routes
.
add
(
'
/catalog/all
'
,
nextLevel
,
methods
.
showCatalogAll
,
$
(
this
));
$
.
router
.
start
(
params
.
route
,
nextLevel
);
});
},
...
...
@@ -281,7 +286,7 @@
listComputers
:
function
()
{
$
(
this
).
vifib
(
'
render
'
,
'
server.list
'
);
},
refreshRowInstance
:
function
()
{
return
this
.
each
(
function
()
{
var
url
=
$
(
this
).
find
(
'
a
'
).
vifib
(
'
extractInstanceURIFromHref
'
);
...
...
@@ -348,7 +353,7 @@
statusCode
:
statusCode
});
},
listInvoices
:
function
()
{
$
(
this
).
vifib
(
'
render
'
,
'
invoice.list
'
);
},
...
...
@@ -424,7 +429,7 @@
$
(
this
).
html
(
ich
[
template
](
data
,
true
));
});
},
getRender
:
function
(
template
,
data
)
{
return
ich
[
template
](
data
,
true
);
},
...
...
vifib/static/js/jquery.urljs.js
View file @
4b8c8371
...
...
@@ -23,7 +23,20 @@ $.extend({
},
},
i
=
this
.
list
[
level
].
length
;
this
.
list
[
level
][
i
]
=
r
;
if
(
this
.
exist
(
r
)
===
false
)
{
this
.
list
[
level
][
i
]
=
r
;
}
},
exist
:
function
(
r
)
{
var
found
=
false
,
i
=
0
;
while
(
i
<
this
.
list
[
r
.
level
].
length
&&
found
===
false
)
{
if
(
this
.
list
[
r
.
level
][
i
].
route
===
r
.
route
)
{
found
=
true
;
}
i
+=
1
;
}
return
found
;
},
clean
:
function
(
level
)
{
...
...
@@ -34,14 +47,16 @@ $.extend({
this
.
list
=
this
.
list
.
slice
(
0
,
0
);
},
search
:
function
(
hash
)
{
search
:
function
(
hash
,
level
)
{
var
stop
=
false
,
i
,
j
,
regex
,
result
,
extracted
;
level
=
level
||
0
;
i
=
this
.
list
.
length
-
1
;
while
((
stop
===
false
)
&&
(
i
>=
0
))
{
hash
.
route
=
hash
.
route
===
"
undefined
"
?
"
/
"
:
hash
.
route
;
while
((
stop
===
false
)
&&
(
i
>=
level
))
{
j
=
0
;
while
((
stop
===
false
)
&&
(
j
<
this
.
list
[
i
].
length
))
{
extracted
=
$
.
router
.
extractKeys
(
this
.
list
[
i
][
j
].
route
);
...
...
@@ -54,12 +69,25 @@ $.extend({
hash
[
extracted
.
keys
[
k
]]
=
result
[
k
];
}
this
.
current
=
this
.
list
[
i
][
j
];
this
.
clean
(
this
.
list
[
i
][
j
].
level
+
1
);
console
.
log
(
this
.
list
[
i
][
j
].
route
)
this
.
list
[
i
][
j
].
callback
(
hash
);
}
j
+=
1
;
}
i
-=
1
;
}
},
isLastLevel
:
function
()
{
return
this
.
current
.
level
===
(
this
.
list
.
length
-
1
);
}
},
start
:
function
(
hash
,
level
)
{
var
hashInfo
=
this
.
parseHash
(
hash
);
if
(
$
.
router
.
routes
.
current
.
route
!==
hashInfo
.
route
)
{
this
.
routes
.
search
(
hashInfo
,
level
);
}
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment