-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from AdFabConnect/refactor_save_action
Refactor save action
- Loading branch information
Showing
18 changed files
with
402 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { | ||
cmsData | ||
} from '../../' | ||
|
||
export function getPercentOfRequiredTagsFilled(text, json) { | ||
var regAbe = /{{abe[\S\s].*?key=['|"]([\S\s].*?['|"| ]}})/g | ||
var matches = text.match(regAbe) | ||
var requiredValue = 0 | ||
var complete = 0 | ||
if(typeof matches !== 'undefined' && matches !== null){ | ||
Array.prototype.forEach.call(matches, (match) => { | ||
if(typeof match !== 'undefined' && match !== null) { | ||
|
||
var keyAttr = cmsData.regex.getAttr(match, 'key') | ||
var requiredAttr = cmsData.regex.getAttr(match, 'required') | ||
if(requiredAttr === 'true') { | ||
requiredValue++ | ||
|
||
var minAttr = cmsData.regex.getAttr(match, 'min-length') | ||
minAttr = (minAttr !== '') ? minAttr : 0 | ||
|
||
if(typeof json[keyAttr] !== 'undefined' && json[keyAttr] !== null && json[keyAttr] !== '') { | ||
if(minAttr > 0) { | ||
if(json[keyAttr].length >= minAttr) { | ||
complete++ | ||
} | ||
}else { | ||
complete++ | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
return Math.round((requiredValue > 0) ? complete * 100 / requiredValue : 100) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.